INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Stored Procedures

How to generate a random password by Malchik
Posted: 26 Aug 09

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))

Back to Microsoft SQL Server: Programming FAQ Index
Back to Microsoft SQL Server: Programming Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close