Difference between revisions of "Random password generator"
From Scriptwiki
m |
m (removed white rules) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
This script will allow you to generate a random password of required length and using characters you want to. | This script will allow you to generate a random password of required length and using characters you want to. | ||
+ | ; Written by Vliedel | ||
+ | ; Contact at irc.quakenet.org -> #help.script | ||
; Usage: $pwgen(length,used characters) | ; Usage: $pwgen(length,used characters) | ||
; Examples | ; Examples | ||
Line 10: | Line 12: | ||
; if a space (chr 32) is in the used characters, the returned password could be too short | ; if a space (chr 32) is in the used characters, the returned password could be too short | ||
; because mirc cuts of double spaces and spaces at the beginning and end of the returned password | ; because mirc cuts of double spaces and spaces at the beginning and end of the returned password | ||
− | + | ||
− | + | ||
[[alias]] pwgen { | [[alias]] pwgen { | ||
; first we check if this alias is used as identifier | ; first we check if this alias is used as identifier | ||
if (![[$isid]]) { [[return]] } | if (![[$isid]]) { [[return]] } | ||
− | ; also check if the length is | + | ; also check if the length is not 0 |
− | if ([[$int]]([[$1]]) == 0) { return } | + | if ([[$int]]([[$1-|$1]]) == 0) { return } |
; the next part will fill &chars with characters that can be picked to make the password | ; the next part will fill &chars with characters that can be picked to make the password | ||
; | ; | ||
Line 44: | Line 46: | ||
while (%i > 0) { | while (%i > 0) { | ||
; again we use a binvar so we can add spaces | ; again we use a binvar so we can add spaces | ||
− | bcopy &pw %i &chars $rand(1,$bvar(&chars,0)) 1 | + | [[bcopy]] &pw %i &chars $rand(1,$bvar(&chars,0)) 1 |
dec %i | dec %i | ||
} | } |
Latest revision as of 14:15, 24 March 2007
This script will allow you to generate a random password of required length and using characters you want to.
; Written by Vliedel ; Contact at irc.quakenet.org -> #help.script ; Usage: $pwgen(length,used characters) ; Examples ; $pwgen(10,a-z A-Z) ; $pwgen(30,0-5 ! . @) ; $pwgen(20,a-z 0-9 0-9) ; $pwgen(17,0-9 $chr(36) $+ - $+ $chr(41)) ; **Note** ; if a space (chr 32) is in the used characters, the returned password could be too short ; because mirc cuts of double spaces and spaces at the beginning and end of the returned password alias pwgen { ; first we check if this alias is used as identifier if (!$isid) { return } ; also check if the length is not 0 if ($int($1) == 0) { return } ; the next part will fill &chars with characters that can be picked to make the password ; ; we cycle the different sets of "used characters" var %i = $numtok($2,32) while (%i > 0) { var %set = $gettok($2,%i,32) ; get the ascii values of the two characters var %asc1 = $asc($left(%set,1)) , %asc2 = $asc($right(%set,1)) var %j = $iif(%asc1 < %asc2,%asc1,%asc2) , %max = $iif(%asc1 < %asc2,%asc2,%asc1) ; we will loop from the smallest ascii number to the largest while (%j <= %max) { ; we add the ascii value to the &chars binvar ; we use a binvar so we won't get troubles with the maximum length of a variable bset &chars $calc($bvar(&chars,0) + 1) %j inc %j } dec %i } ; check if &chars is not empty if ($bvar(&chars,0) == 0) { return } ; ; now we filled &chars we randomly pick characters out of &chars to make the password var %i = $iif($abs($int($1)) > 900,900,$v1) ; we do this $1 times, as long as its not larger then 900 ; (wich is approximate the limit of commands) while (%i > 0) { ; again we use a binvar so we can add spaces bcopy &pw %i &chars $rand(1,$bvar(&chars,0)) 1 dec %i } ; to avoid the "space bug" (see the note), you may want to use the binvar ; in that case we return the binvar name, uncomment the next line ; return &pw return $bvar(&pw,1,$bvar(&pw,0)).text }