SQL - How to generate a password
August 4th, 2008 by whit3kr0w

If you have the need of a piece of SQL code to generate a password you can use this one:
declare @pw varchar(8)
declare @count int
declare @characterpool varchar(50)
set @characterpool = 'abcdefghijkmnpqrstuvwxyz0123456789'
set @count = 0
set @pw = ''
while @count <= 8
begin
set @pw = @pw + SUBSTRING(@characterpool,
CAST(ABS(CHECKSUM(NEWID()))*RAND(@count) as int)%LEN(@characterpool)+1,1)
set @count = @count + 1
end
This generates an eight digit password using the characters a-z and numbers. If you want you can change the length of the password by changing the ‘8′ to the desired number in the lines:
declare @pw varchar(8)
while @count <= 8
Hope you find this useful.
Thanks to GM for the code.
Posted in Programming
Geekie.net RSS feed