I want to create a function which generates a random password for given length. It should generate at least 8 length password which includes at least 2 number, 3 letter, 3 special character like for example: a8b*4/c1+
I found some code and mixed it up but I couldn't do it properly Could anyone help me about how to create this function.
CREATE FUNCTION random_password(@length ID)
RETURNS VARCHAR(8)
AS
BEGIN
-- Declare the variables here
DECLARE @Result VARCHAR(8)
DECLARE @BinaryData VARBINARY(8)
DECLARE @CharacterData VARCHAR(8)
DECLARE @randval VARCHAR(8)
randval = CRYPT_GEN_RANDOM(8)
SELECT @BinaryData = randval
FROM vRandom
Set @CharacterData=cast ('' as xml).value ('xs:base64Binary(sql:variable("@BinaryData"))',
'varchar (max)')
SET @Result = @CharacterData
-- Return the result of the function
RETURN @Result
END
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…