473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Random Password PHP code help req.. only gettinh 3 letters?

Hi,

Wondering if anyine can help with the membership PHP script I lifted
from a tutorial. I'm new to PHP and have this system up and running but
my password only come out at three letters and sometime have a space in
them?? Anyway this is the code:

function makeRandomPassword($len = 8,$upper = 1,$number = 1) {
$salt = "abcdefghijklmnopqrstuvwxyz";
$uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$numbers = "1234567890";
if ($upper) $salt .= $uppercase;
if ($number) $salt .= $numbers;

srand((double)microtime()*1000000);
$i = 0;
while ($i <= $len) {
$num = rand() % strlen($salt);
$tmp = substr($salt, $num, 1);
$pass = $num . $tmp;
$i++;
};
return $pass;
};

$random_password = makeRandomPassword();

$db_password = md5($random_password);

Any ideas.. I need maybe 5 letters with no spaces...

Thanks
Col

Sep 14 '06 #1
4 1858
*** techcs escribió/wrote (14 Sep 2006 12:58:34 -0700):
Wondering if anyine can help with the membership PHP script I lifted
from a tutorial. I'm new to PHP and have this system up and running but
my password only come out at three letters and sometime have a space in
them??

I'd replace this part...
$i = 0;
while ($i <= $len) {
$num = rand() % strlen($salt);
$tmp = substr($salt, $num, 1);
$pass = $num . $tmp;
$i++;
};
.... with this code:

$pass='';
$max=strlen($salt)-1;
for($i=0; $i<$len); $i++){
$pass.=$salt{mt_rand(0, $max)};
}
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 14 '06 #2
Hi, thanks for that but I get a parse error with that code, maybe I
have to change some of the other bit to match, will have another
look...

Cheers
Col
Alvaro G. Vicario wrote:
*** techcs escribió/wrote (14 Sep 2006 12:58:34 -0700):
Wondering if anyine can help with the membership PHP script I lifted
from a tutorial. I'm new to PHP and have this system up and running but
my password only come out at three letters and sometime have a space in
them??


I'd replace this part...
$i = 0;
while ($i <= $len) {
$num = rand() % strlen($salt);
$tmp = substr($salt, $num, 1);
$pass = $num . $tmp;
$i++;
};

... with this code:

$pass='';
$max=strlen($salt)-1;
for($i=0; $i<$len); $i++){
$pass.=$salt{mt_rand(0, $max)};
}
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 14 '06 #3
*** techcs escribió/wrote (14 Sep 2006 14:44:16 -0700):
Hi, thanks for that but I get a parse error with that code, maybe I
have to change some of the other bit to match, will have another
look...
I didn't test the code. Just remove the unexpected ')'.

>$pass='';
$max=strlen($salt)-1;
for($i=0; $i<$len); $i++){
$pass.=$salt{mt_rand(0, $max)};
}
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 14 '06 #4
Thanks Alvaro,

That works great.. Much appreciated..

Col
*** techcs escribió/wrote (14 Sep 2006 14:44:16 -0700):
Hi, thanks for that but I get a parse error with that code, maybe I
have to change some of the other bit to match, will have another
look...

I didn't test the code. Just remove the unexpected ')'.

$pass='';
$max=strlen($salt)-1;
for($i=0; $i<$len); $i++){
$pass.=$salt{mt_rand(0, $max)};
}

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andre | last post by:
I'm trying to write a Password generating program which will fill one of the fields in our Accounts Table with an eight-digit password made up of numerals, upper and lower case letters. I'm...
2
by: Joe | last post by:
Hi, I want to generate a random password every time a new user account is created. I want to include small and capital letters and 0 to 9 digits. Can someone give me some idea as how should I do...
7
by: MattB | last post by:
I have the following code to generate random passwords for new users of an application. Const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvwxyz1234567890" Dim r As Int16, i As...
14
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
1
by: Jeff | last post by:
hey gang. I have a code to create a random string of letters. The number of them can be whatever I desire. what i would like to do, is have it both letters and integers. how would i modify...
3
by: John | last post by:
Hi How can I generate a random password of 8 characters (digits and letters) in vb? Thanks Regards
2
by: DarthPeePee | last post by:
Hello everyone. I am working on a Password Strength Meter and I am running into 1 problem that I would like to fix. When pressing the "Clear Password & Try Again" button, the password clears...
5
by: ashurack | last post by:
I found a stored procedure online a while back and want to inplement it. The only problem is that it doesn't check to see if the number generated is currently in use in the DB. I know it's really...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.