Random Password Generator

There can be several ways to generate a random password. Assume that your password should contain alphabets, numbers and some special characters. The following is one of the ways.

 

declare @password varchar(20)
set @password=''

SELECT
(
SELECT +password FROM
(
     select top 8 char(number) as password from master..spt_values
     where type=‘p’ and number between 48 and 122
     order by newid()
) as t
FOR XML PATH()
) as password

The above creates some random password with 8 characters in length. If you want to change the length, change the number in the TOP clause.

The password I got running this code is T5:DZ?ow

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s