xxxxxxxxxx
function CreatePassword(PassLenght) {
const Lenght = parseInt(PassLenght)
const Charecters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
let Password = "";
for (var i = 0, n = Charecters.length; i < Lenght; ++i) { Password += Charecters.charAt(Math.floor(Math.random() * n)); }
console.log(Password)
return Password;
}
CreatePassword(18)
xxxxxxxxxx
function passwordGenerator(length) {
const chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789012345678901234567890123456789!@#$%&*()_-+=!@#$%&*()_-+=!@#$%&*()_-+=!@#$%&*()_-+=";
const password = [Array(length)].reduce((accumulator, _element) => {
const randomIndex = Math.floor(Math.random() * chars.length);
return accumulator + chars[randomIndex];
}, "");
return password;
}
xxxxxxxxxx
function rand_string( $length ) {
$str = "";
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
//and call the function this way:
$mypass = rand_string(10);
xxxxxxxxxx
from random import randint
def create_random_chars(charCount):
return "".join(chr(randint(33,126)) for i in range(charCount))
print(create_random_chars(10))
# Use Source to compile
xxxxxxxxxx
import random
import string
total = string.ascii_letters + string.digits + string.punctuation
length = 16
password = "".join(random.sample(total, length))
print(password)
xxxxxxxxxx
@echo off
set "chars=1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$@[/\]-_{}+"
call :getStringLength chars charsLength
set /p "passLength=Enter password length to generate: "
for /l %%i in (1,1,%passLength%) do (
call set /a r=%%random%%%%%%charsLength%%+1
call call <nul set /p "=%%%%chars:~%%r%%,1%%%%"
)
echo(&pause
goto:eof
REM ========== FUNCTIONS ==========
:getStringLength (string input, out int length)
setlocal enableDelayedExpansion
set "s=#!%~1!"
set "len=0"
for %%n in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%n,1!" neq "" (
set /a "len+=%%n"
set "s=!s:~%%n!"
)
)
endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len%
exit /b
We define the characters allowed (removed unsafe chars) and get the total number of characters
Prompt user for length and set that as total iterations count
Generate a random number between 1 and total chars
Pick the character at the index of the random number
xxxxxxxxxx
#python
from random import randint
import pyperclip
allSymbols = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '- ', '=', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', ' (', ' )', ' ¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹', '⁰', '¡', '¤', '€', '¼', '½', ' ¾', '‘', '’', 'æ', '©', '®', 'þ', '«', '»', '"', "'", 'ß', '§', 'ð', 'œ', 'Æ', 'Œ', 'ø', '¶', 'Ø', '°', '¿', '£', '‘¥', '÷', '×', '/', '?' ]
password = ' '
lenSymbols = len(allSymbols)
recycleMe = int(input("how much characters do you want your password to be? "))
for i in range(recycleMe):
password = password + allSymbols[randint(0, lenSymbols)]
print(password)
#pyperclip.copy(password)
#print("copied to clipboard")
xxxxxxxxxx
function password(length,base64) {
//let num=typeof length=='number'?Math.round(Math.random()*length*36):Math.round(Math.random()*10*36)
let ret='';for(let i=0;i<length;i++){ret+=Math.round(Math.random()*36).toString(36)}
return base64?(btoa(ret)):ret
}