Difference between revisions of "Random Password Generator"
Jump to navigation
Jump to search
Kireji Haiku (talk | contribs) (added some missing characters) |
m (<lsl> tag to <source>) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Code: | Code: | ||
< | <source lang="lsl2"> | ||
// Generate Passwords based on String length | // Generate Passwords based on String length | ||
// Free to use, share and remix. | // Free to use, share and remix. | ||
Line 6: | Line 6: | ||
string randomPassword(integer length) | string randomPassword(integer length) | ||
{ | { | ||
string | string CharSet = "abcdefghijkmnpqrstuvwxyz23456789"; // omitting confusable characters | ||
string | string password; | ||
integer CharSetLen = llStringLength(CharSet); | |||
// Note: We do NOT add 1 to the length, because the range we want from llFrand() is 0 to length-1 inclusive | |||
while( | while (length--) | ||
{ | { | ||
integer rand = (integer) llFrand(CharSetLen); | |||
integer | password += llGetSubString(CharSet, rand, rand); | ||
} | } | ||
return password; | |||
return | |||
} | } | ||
default | default | ||
{ | { | ||
touch_start(integer num) | |||
{ | { | ||
llSay(0, randomPassword(10)); | |||
llSay( | |||
} | } | ||
} | } | ||
</ | </source> |
Latest revision as of 07:44, 25 January 2015
Code:
// Generate Passwords based on String length
// Free to use, share and remix.
string randomPassword(integer length)
{
string CharSet = "abcdefghijkmnpqrstuvwxyz23456789"; // omitting confusable characters
string password;
integer CharSetLen = llStringLength(CharSet);
// Note: We do NOT add 1 to the length, because the range we want from llFrand() is 0 to length-1 inclusive
while (length--)
{
integer rand = (integer) llFrand(CharSetLen);
password += llGetSubString(CharSet, rand, rand);
}
return password;
}
default
{
touch_start(integer num)
{
llSay(0, randomPassword(10));
}
}