Generare parola random

Configurare noua (How To)

Situatie

Mai jos este o procedura ce genereaza parole random si in care se pot stabili criteriile de complexitate prin cei doi parametri: unul ce seteaza lungimea si celalalt ce seteaza ce fel de caractere foloseste la generarea parolei.

Solutie

create procedure GenerareParolaRandom_prc

@passlen int = 10,
@charset int = 2

— 0 alfabetic
— 1 alfanumeric
— 2 alfanumeric + carcatere speciale

as

if (@passlen > 8000 or @passlen < 1)
select @passlen = 10

declare @password varchar(8000), @string varchar(256), @numbers varchar(10), @extra varchar(50),
@stringlen int, @index int

select @string = ‘ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz’
select @numbers = ‘23456789’
select @extra = ‘”@#\$%&>_!=?<‘

if @charset = 2
select @string = @string + @numbers + @extra
else if @charset = 1
select @string = @string + @numbers

select @stringlen = len(@string)

while (@passlen > 0)
begin
select @index = (abs(checksum(newid())) % @stringlen) + 1
select @passlen = @passlen – 1
end