Random Password Generator
We have an environment with over 300 sql server instances and every 90 days we need to cycle “sa”. To help in this endeavor I created a script to generate random passwords. The passwords can be any length you require (while @idx < n). I use this script to generate a random password, reset “sa” and then write the new password out to an encrypted column in SQL Server.
declare @idx as int
declare @randomPwd as nvarchar(64)
declare @rnd as float
select @idx = 0
select @randomPwd = N”
select @rnd = rand((@@CPU_BUSY % 100) + ((@@IDLE % 100) * 100) +
(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))
while @idx < 8 –64
begin
select @randomPwd = @randomPwd + char((cast((@rnd * 83) as int) + 43))
–PRINT @randomPwd –debug
select @idx = @idx + 1
elect @rnd = rand()
end
Select
@randomPwd