tags:

views:

38

answers:

5

Hi,

I need to take a user's email address and somehow manipulate the value to come up with an auto-generated password. I want to make sure that I can re-create the same password whenever a user needs to retrieve their password.

Is there a standard way of doing this? Is this what a "hash" is? I would be greatly appreciative if someone could point me in the right direction! :) Once I know where to look, I can do the research myself.

Thanks!

Sunny

+1  A: 

A hashing function does do what you're looking for - it takes some input x and generates a digest d that will be the same whenever you give it input x again.

A better definition from wikipedia, that explains this property:

Determinism

A hash procedure must be deterministic—meaning that for a given input value it must always generate the same hash value. In other words, it must be a function of the hashed data, in the mathematical sense of the term. This requirement excludes hash functions that depend on external variable parameters, such as pseudo-random number generators that depend on the time of day. It also excludes functions that depend on the memory address of the object being hashed, if that address may change during processing (as may happen in systems that use certain methods of garbage collection), although sometimes rehashing of the item can be done.

However, if this is for password retrieval, I would advise against it. Instead, I would recommend the approach of sending them a link to reset their password, and then have them reset their password.

birryree
+3  A: 

Yes, that's what a "hash" is. However, I would strongly caution against this approach, because it means that someone who's good at cryptographic analysis could potentially generate the password for any user on the system, just by knowing their email address.

Standard practice in the case you're suggesting is to actually reset the user's password with a new, random password when they forget their password. That keeps their previous password "safe," so that someone happens to intercept the email with their password, it will only contain a random password rather than a password that the user very likely uses for every other website they log in to.

After a password reset, users should be encouraged to change their password when they first log in.

StriplingWarrior
+1  A: 

If you are doing some sort of password reset system, you should just randomly generate a password to their email and than force them to change it on initial login. If they need to reset their password at some other time, than they can go through the same process again.

Casey
+1  A: 

Something like the md5 function in PHP would be a good place to start. However, why would you need to recreate the same autogenerated password if the user lost it ? Personally, it would make more sense to just generate a new random one.

wildpeaks
+1  A: 

A Hash is like a fingerprint. If you have the original value (the password for example), you can get the fingerprint and compare to the one you have in your database. But with the fingerprint you have in the database, you can't recreate the original value (you can't create an human from a fingerprint).

It seems to be what you want. But even so it could be not what you need. Generating a password from the hash of an email address means that anyone that know how you hash your email address will potentially know every password.

If you're looking to a password recovery system, you should instead use a Self-service password reset system.

  1. The users says that he forgot the password
  2. You send a unique key (that you store in your database) to this user by a secure mean (usually mail).
  3. The user confirm that he forgot the password by giving you the unique key previously used. This way you're sure that the user is the owner.
  4. You generate a totally random password that you store (in the hashed form) in your database and send it to the owner by the previously used secure mean.
Colin Hebert