This SP will returns a random password composed of 3 uppercase letters, 2 lowercase letters and a number. It is easy to modify and use variables to control the lenght of each section
CREATE PROCEDURE p_GenerateRandomPassword(@PWD AS VARCHAR(15) OUTPUT)
AS
SET NOCOUNT ON
DECLARE @Count AS TINYINT
SET @Count = 0
SET @PWD = ''
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Randomize the first 3 letters in uppercase
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
WHILE @Count <= 2
BEGIN
SET @PWD = @PWD + CHAR(ROUND(((90 - 65 -1) * RAND() + 65), 0))
SET @Count = @Count + 1
END
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Randomize the next 2 letters in lowercase
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SET @Count = 0
WHILE @Count <= 1
BEGIN
SET @PWD = @PWD + LOWER(CHAR(ROUND(((90 - 65 -1) * RAND() + 65), 0)))
SET @Count = @Count + 1
END
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Randomize add a number
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SET @PWD = @PWD + CAST(ROUND(((25 - 1 -1) * RAND() + 9), 0) AS VARCHAR(3))
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.