Difference between revisions of "Random Password Generator"

From Second Life Wiki
Jump to navigation Jump to search
(added some missing characters)
(while loop variable name passwordToBeReturned was incorrect)
Line 9: Line 9:
     string passwordToBeReturned;
     string passwordToBeReturned;


     while(llStringLength(rPass) < length)
     while(llStringLength(passwordToBeReturned) < length)
     {
     {
         // because llFrand is [0, mag)
         // because llFrand is [0, mag)

Revision as of 06:09, 9 August 2013

Code: <lsl> // Generate Passwords based on String length // Free to use, share and remix.

string randomPassword(integer length) {

   string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
   string passwordToBeReturned;
   while(llStringLength(passwordToBeReturned) < length)
   {
       // because llFrand is [0, mag)
       integer upperLimit = llStringLength(letters) + 1;
       integer rand = llFloor(llFrand(upperLimit));
       passwordToBeReturned += llGetSubString(letters, rand, rand);
   }
   return passwordToBeReturned;

}

default {

   state_entry()
   {
       // PUBLIC_CHANNEL has the integer value 0
       llSay(PUBLIC_CHANNEL, randomPassword(10));
   }

} </lsl>