Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

sql server - Create a function generates random password in SQL

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...