473,407 Members | 2,315 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,407 software developers and data experts.

Random password generation

40
I want to generate password randomly and send to mysql database using PHP..i have got the following function for generating password but doesn't know how to incorporate in my registration form and where to call that function and update password field in database..please help me..
Expand|Select|Wrap|Line Numbers
  1.     function generatePassword ( $length = 8 ) {
  2.     // start with a blank password
  3.     $password = “”;
  4.  
  5.     // define possible characters
  6.     $possible = “0123456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ!@#$%^&*”;
  7.  
  8.     // set up a counter
  9.     $i = 0;
  10.  
  11.     // add random characters to $password until $length is reached
  12.     while ($i < $length) {
  13.     // pick a random character from the possible ones
  14.     $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
  15.  
  16.     // we don’t want this character if it’s already in the password
  17.     if (!strstr($password, $char)) {
  18.     $password .= $char;
  19.     $i++;
  20.     }
  21.     }
  22.     // done!
  23.     return $password;
  24.     }
  25.  
where should i call this function generatePassword????
Jun 16 '09 #1
3 1542
hsriat
1,654 Expert 1GB
Keep this function at the bottom of your PHP script, or in some other dedicated .php file for this function and include that PHP script in your present script.

Then use this function like
Expand|Select|Wrap|Line Numbers
  1. $new_password = generatePassword (10); //whatever length
  2. $sql = mysql_query("INSERT INTO ..... .... (`password`, ... ... ...) VALUES ($new_password, ... ... ...)")
Jun 16 '09 #2
Markus
6,050 Expert 4TB
You could just use one of the built in random functions or hash functions.
Jun 16 '09 #3
divyac
40
thank hsriat..its working.... :)
Jun 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of...
0
by: Adam Carpenter | last post by:
Hello, I am having some problems with these functions which are to be part of the forgotten password system for a website. I am sure it is something simple but I can't see it. I would be...
4
by: Dimos | last post by:
Hello All, I need some help with random number generation. What I need exactly is: To create a few thousand numbers, decimal and integers, between 5 and 90, and then to export them as a...
24
by: NoName | last post by:
Perl: @char=("A".."Z","a".."z",0..9); do{print join("",@char)}while(<>); !!generate passwords untill U press ctrl-z Python (from CookBook):
3
by: Army1987 | last post by:
Is there anything wrong with this program? It seems to behave strangely if I give stdin EOF when asked for the character set... /* BEGIN pwdgen.c */ #include <stdio.h> #include "random.h"...
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
0
by: sweatha | last post by:
Hi Friends I have designed a form with a label box named 'Label30' and text box named 'TextBox21'. Then I have generated the random number in the label box using the coding in form load event as ...
16
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers...
17
by: almurph | last post by:
Hi, Hope you can help me with this one. I am trying to create random number between 0 and 1 inclusive of cryptographiuc quality. The problems is though - I don't know how! Here is what I have so...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.