Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2004, 04:43 PM
Authorized User
 
Join Date: May 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ruhin Send a message via AIM to ruhin Send a message via MSN to ruhin Send a message via Yahoo to ruhin
Default Random+Encrypted Password

How can i generate "alphabetic+numeric+specialchars" combined password.
I also need the coding for encrypting the password.
Kindly ,help me!
 
Old June 28th, 2004, 02:07 PM
Authorized User
 
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if you want to generate random characters, you can use the rand() function while setting the characters into an array. that is, you feed the characters (0-9, a-z and anything else you want) into an array
$characters = array("a", "b", "c" ... and so on)
then you use rand() to select an index number in the array
$first_index = rand(1, 100) (this is assuming you have 100 characters in the array)
then assign that character to a variable
$first_char = $characters[$first_index]
and so on for as many characters as you want in a password.

when you've generated enough characters, you can combine/concatenate them into a variable which will be the password
$random_pass = $first_char . $second_char...and so on
this is just way one of doing it, there are others which you may like better, such as using a counter inside a loop to count generated characters until you reach a predetermined number of characters, after which you combine them into a single password variable, or you may even "assemble" the password during each iteration, one character at a time.

now, as for encrypting the password, there are several ways to do this, you can hash it if you want a non-reversible encryption of it, or you can use a reversible encryption. both have their pros and cons. non-reversible can't be "hacked" because you can't take the hash and work out the password used; while reversible methods can be used to send a user back his/her password if they forget it.

using the md5() function to hash a password, it would look something like this
$pass_hash = md5($pass_cleartext)
using the sha1() function, you write it the same way
$pass_hash = sha1($pass_cleartext)
both md5() and sha1() are non-reversible methods.

however, if you want to learn more about reversible encryption with PHP, check out what the PHP manual has to say about the mcrypt() function at http://www.php.net/manual/en/ref.mcrypt.php





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Encrypted Password cancer10 Classic ASP Databases 0 April 10th, 2007 11:12 PM
Encrypted password harini19 Java Basics 0 February 15th, 2006 07:29 AM
Encrypted Password field knight Classic ASP Databases 7 June 28th, 2004 12:35 PM
password in encrypted form mateenmohd SQL Server 2000 4 January 24th, 2004 07:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.