I am trying to create a SQL procedure that hashes password inputs. This code won't run and I am not getting any useful response errors.
The first part creates the table, the second creates the procedure. When I call on my procedure in the third part it send the values into the procedure. There the password is supposed to be hashed using SHA2_512 and inserted into the table we made eralier.
I used online research to make this code, the parts I don't get is:
The N before my values
The SetNoCount
The @responsemessage
-- makes Admin table
CREATE TABLE IF NOT EXISTS `AdminUser` (
`AdminID` smallint(6) NOT NULL AUTO_INCREMENT,
`Username` char(15) NOT NULL,
`PasswordHash` BINARY(64) NOT NULL,
`Fornavn` char(30) NOT NULL,
`Etternavn` char(40) NOT NULL,
`Email` char(40) NOT NULL,
PRIMARY KEY (`AdminID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Makes hashing procedure
CREATE OR REPLACE PROCEDURE vm_ski.addAdmin
@pUsername NVARCHAR(50),
@pPassword NVARCHAR(50),
@pFornavn NVARCHAR(30),
@pEtternavn NVARCHAR(40),
@pEmail NVARCHAR(40),
@responseMessage NVARCHAR(250)='' OUTPUT
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
INSERT INTO vm_ski.AdminUser (Username, PasswordHash, Fornavn, Etternavn, Email)
VALUES(@pUsername, HASHBYTES('SHA2_512', @pPassword), @pFornavn, @pEtternavn, @pEmail)
SET @responseMessage='Success'
END TRY
BEGIN CATCH
SET @responseMessage=ERROR_MESSAGE()
END CATCH
END;
-- Admin example
DECLARE @responseMessage NVARCHAR(250)
EXECUTE vm_ski.addAdmin
@pUsername = N'sondre',
@pPassword = N'example'
@pFornavn = N'Sondre'
@pEtternavn = N'Morgendal'
@pEmail = N'sondre.example@gmail.com'
;