Skip to content

Instantly share code, notes, and snippets.

@David263
Created July 20, 2022 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save David263/b88b1cd399d4104ebc3dc909303962ba to your computer and use it in GitHub Desktop.
Save David263/b88b1cd399d4104ebc3dc909303962ba to your computer and use it in GitHub Desktop.
Generate good passwords for use on mobile devices/smartphones
<?php
/*
Generate good passwords for mobile use
Created by David Spector, Springtime Software 2022
Public Domain
ver=7/20/22 released
Tested only on Windows 10: uses PHP function random_int
For run length 0, passwords are 0 characters long, and there are 1 unique passwords possible
For run length 1, passwords are 3 characters long, and there are 4608 unique passwords possible
For run length 2, passwords are 6 characters long, and there are 97844723712 unique passwords possible
For run length 3, passwords are 9 characters long, and there are 9.5735899582776E+21 unique passwords possible
For run length 4, passwords are 12 characters long, and there are 4.3164300183536E+36 unique passwords possible
For run length 5, passwords are 15 characters long, and there are 8.9678235849214E+54 unique passwords possible
*/
define("RUN_LEN",3); // 2: length of pwd=6, 3: len=9, 4: len=12
$sets=['ABCDEGHJKLMNOPQRSTUVWXYZ',
'abcdeghijkmnopqrstuvwxyz',
'23456789'];
define("SET_LEN",3);
$perms=[[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]];
define("PERMS_LEN",6);
define("SETS",$sets);
define("PERMS",$perms);
// ver=7/20/22
// Length of result pwd is SET_LEN*RUN_LEN
function GenPassword()
{
$pwd='';
// Select a random permutation of the char type sets
$perm=PERMS[random_int(0,PERMS_LEN-1)];
for ($i=0; $i<SET_LEN; $i++)
{
$setNr=$perm[$i];
$set=SETS[$setNr];
$setSize=strlen($set);
for ($j=0; $j<RUN_LEN; $j++)
$pwd.=$set[random_int(0,$setSize-1)];
}
} // GenPassword
// Tests
for ($i=0; $i<100; $i++)
{
//$pwd=GenPassword();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment