Skip to content

Instantly share code, notes, and snippets.

@lusareal
Created July 21, 2023 11:12
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 lusareal/d9153081f4b488e48a5b7f63c8db5533 to your computer and use it in GitHub Desktop.
Save lusareal/d9153081f4b488e48a5b7f63c8db5533 to your computer and use it in GitHub Desktop.
php online pasword generator
<?php
function generate_password($length = 16, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'){
$str = '';
$max = mb_strlen($characters, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$str .= $characters[random_int(0, $max)];
}
return $str;
}
echo generate_password(16, '*&^%$#@!0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
@lusareal
Copy link
Author

For nodejs

const crypto = require('crypto');

function generatePassword(length = 16, characters = '*&^%$#@!0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
    let password = '';
    for (let i = 0; i < length; i++) {
        password += characters[crypto.randomInt(0, characters.length)];
    }
    return password;
}

console.log(generatePassword(16, '*&^%$#@!0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment