Last active
July 7, 2024 09:12
-
-
Save joshhartman/1507069 to your computer and use it in GitHub Desktop.
Human Readable Password Generator (Requires PHP 7.1+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function randomPassword( $len = 10, $ucfirst = true, $spchar = true ){ | |
/* Programmed by Christian Haensel | |
* [email protected] | |
* http://www.chftp.com | |
* | |
* Exclusively published on weberdev.com. | |
* If you like my scripts, please let me know or link to me. | |
* You may copy, redistribute, change and alter my scripts as | |
* long as this information remains intact. | |
* | |
* Modified by Josh Hartman on 2010-12-30. | |
* Last modified: 2023-03-01 | |
* Thanks to JKDos for suggesting improvements. | |
*/ | |
if ( $len >= 8 && ( $len % 2 ) !== 0 ) { // Length parameter must be greater than or equal to 8, and a multiple of 2 | |
$len = 8; | |
} | |
$length = $len - 2; // Makes room for a two-digit number on the end | |
$conso = array( 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' ); | |
$vowel = array( 'a', 'e', 'i', 'o', 'u' ); | |
$spchars = array( '!', '@', '#', '$', '%', '^', '&', '*', '-', '+', '?', '=', '~' ); | |
$password = ''; | |
$max = $length / 2; | |
for ( $i = 1; $i <= $max; $i ++ ) { | |
$password .= $conso[ random_int( 0, 19 ) ]; | |
$password .= $vowel[ random_int( 0, 4 ) ]; | |
} | |
if ( $spchar == true ) { | |
$password = substr( $password, 0, - 1 ) . $spchars[ random_int( 0, 12 ) ]; | |
} | |
$password .= random_int( 10, 99 ); | |
if ( $ucfirst == true ) { | |
$password = ucfirst( $password ); | |
} | |
return $password; | |
} | |
echo randomPassword(); |
You're welcome. Anyone can check it out as-well-as the source by checking: https://jkdos.com/apps/php/passwd-gen/
It is so funny to see my old script still floating around somewhere 👍
It's simple and efficient! 👏
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice additions, thanks for sharing @JKDos