Skip to content

Instantly share code, notes, and snippets.

@opdo
Created February 12, 2020 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opdo/3d5619b6b9222aaf3b40afe900b5852d to your computer and use it in GitHub Desktop.
Save opdo/3d5619b6b9222aaf3b40afe900b5852d to your computer and use it in GitHub Desktop.
Hash Password by Trigger SQL SERVER
-- trigger trên table USER
create trigger [dbo].[trg_AutoCryptPassword] on [dbo].[USER]
for insert, update
as
begin
if UPDATE([Password])
begin
declare @id int
declare @Password varchar(256)
select @Password = [Password], @id = IdUser from inserted
set @Password = dbo.func_CryptData(@Password)
update [USER] set [Password] = @Password where IdUser = @id
end
end
-- hàm hash
create function [dbo].[func_CryptData] (@Data varchar(100))
returns varchar(256)
as
begin
return convert(varchar(256),HASHBYTES('SHA2_256',@Data),2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment