Page 1 of 1
password generation algo
Posted: Thu Sep 18, 2003 1:18 pm
by phpcoder
i want some algorithm to generate password for scratch card my card serial # is atrt from 0001 onward pl help me
Posted: Thu Sep 18, 2003 2:56 pm
by m3rajk
do you have any ideas on how to do it? i have something that does letters and numbers mixed rather well but i'm not simply going to give you something. show me that you've got a clue as to what you're doing and you need to be pointed in a direction, then i will help you get where you want, and if you're close enough just give you what i have
Posted: Thu Sep 18, 2003 3:02 pm
by JAM
Posted: Thu Sep 18, 2003 3:17 pm
by jason
http://www.evilwalrus.com/viewcode.php?codeEx=535 is what I normally use if I need to create on the fly passwords.
Posted: Thu Sep 18, 2003 4:22 pm
by Drachlen
Code: Select all
<?php
for($x=0;$x<32;$x++){
$random = rand(33,105);
$password .= chr($random);
}
echo md5($password);
?>
Posted: Fri Sep 19, 2003 12:33 am
by scorphus
Mixing Jason's and Drachlen's solutions, I came into this:
Code: Select all
<?
function random_password ($length = 0) {
$dx = mt_rand(0, 32 - $length);
$length_ini = empty($length) ? mt_rand(0, 19) : $dx;
$length_fin = empty($length) ? mt_rand(6, 12) : $length;
for ($x = 0; $x < 32; $x++) {
$random = rand(33, 105);
$password .= chr($random);
}
$password = md5($password);
$password = substr(md5($password), $length_ini, $length_fin);
return $password;
}
echo random_password(10);
echo random_password(8);
echo random_password(6);
echo random_password(4);
?>
An output:
Specify the length of the password, from 1 (not really) to 32 in random_password function call. If the $length parameter is set to 0, the function returns a 6 to 12 length password.
Cheers,
Scorphus.
Posted: Fri Sep 19, 2003 9:06 am
by jason
Hey, that's my password!!
Posted: Fri Sep 19, 2003 10:18 am
by scorphus
Sure it is! I think you missed the very first line of my post...
Your function was repeating some passwords from time to time, then I merged Drachlen's solution to yours.
I was in search for such an algo... thanks!
Regards,
Scorphus.
Posted: Fri Sep 19, 2003 10:44 am
by jason
No, I meant, that is my PASSWORD, as in haha, funny funny.
As in one of the 4 examples you displayed was my password. =p