Skip to content

Instantly share code, notes, and snippets.

@alefra88
Last active November 5, 2024 21:54
Show Gist options
  • Save alefra88/89833a45cdfd62bd3d259f75d0ac5f92 to your computer and use it in GitHub Desktop.
Save alefra88/89833a45cdfd62bd3d259f75d0ac5f92 to your computer and use it in GitHub Desktop.
sp en sql server para insertar usuario con password hasheada, se agregó mensaje de error
USE [DB_desde_transact]
GO
/****** Object: StoredProcedure [dbo].[spUsuariosInsertar] Script Date: 05/11/2024 03:52:16 p. m. ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spUsuariosInsertar]
(
@Email varchar(250),
@Password varchar(30)
)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
DECLARE @PasswordHash varbinary(32);
SELECT @PasswordHash = HASHBYTES('SHA2_256', @Password);
INSERT INTO dbo.Usuarios(FechaAlta,Email,Password)
VALUES (GETDATE(), @Email, @PasswordHash)
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
SET @ErrorMessage = ERROR_MESSAGE();
RAISERROR(@ErrorMessage, 16, 1);
END CATCH
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment