The MD5 function
When you’re working with hashed passwords, it might be useful to have the MD5 encryption feature in your database.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ==================================================
-- Author: Mike Bevers
-- Create date: 07/04/2011
-- Description: Hashes a value with the MD5 algorithm
-- ==================================================
CREATE FUNCTION MD5
(
@value varchar(255)
)
RETURNS varchar(32)
AS
BEGIN
RETURN SUBSTRING(sys.fn_sqlvarbasetostr(HASHBYTES('MD5', @value)),3,32);
END
GO
Usage:
select dbo.MD5('test')
-- Will return '098f6bcd4621d373cade4e832627b4f6'
Comments