-
-
Save opdo/3d5619b6b9222aaf3b40afe900b5852d to your computer and use it in GitHub Desktop.
Hash Password by Trigger SQL SERVER
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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