[ create a new paste ] login | about

Link: http://codepad.org/UL8k4aYK    [ raw code | output | fork | 28 comments ]

PHP, pasted on Nov 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function randomPassword() {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 8; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}

echo randomPassword();
?>


Output:
1
NoeGhAhG


Create a new paste based on this one


Comments:
posted by nirasha.dilhani on Jul 7
Thanks for this. this is excellent
reply
posted by plemenity on Sep 28
Thank you :)
reply
posted by sunil@gmail.com on Apr 26
grew
reply
posted by mzennis on Jun 13
wow it works, thx :D
reply
posted by moinshaikh786.1 on Oct 20
Cant we just store the created alphanumeric code in sql database ?
reply
posted by admin on Sep 13
zzzz
reply
posted by 333 on Oct 25

reply
posted by 333 on Oct 25

reply
posted by 333 on Oct 25

reply
posted by 333 on Oct 25

reply
posted by 333 on Oct 25

reply
posted by 333 on Oct 25

reply
posted by 333 on Oct 25
.
reply
posted by 333 on Oct 25
.
reply
posted by 333 on Oct 25
3232323
reply
posted by 333 on Oct 25
NoeGhAhG
reply
posted by NoeGhAhG on Jul 10
NoeGhAhG
reply
posted by sirdash on Dec 15
if we add this"~!@#$%^&*()_+=" to $alphabet
Now very verystrong
reply
posted by qwewqeqweqw on Jun 14
asdsasd
reply
posted by qwewqeqweqw on Jun 14
asasdsd
reply
posted by kako0000000 on Jun 29
reply
posted by hequgobahy on Sep 27
<?php
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}

echo randomPassword();
?>
reply
posted by hequgobahy on Sep 27
hhhhhhhhhh
reply
posted by 545 on Jan 18
1
reply
posted by 545 on Jan 18
545
reply
posted by 545 on Jan 18
555
reply
posted by johanvera on Sep 18
How do I generate a password for each user that is not random? That is the same always ...?
reply
posted by 123qwe4r on Apr 1

reply