Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
1.43/5 (7 votes)
See more:
I'm writting a program to give a user a unique password based on his email address and i found this piece of code online. I'm now trying to reverse the code so that i can get back the email address from the password, pls can anyone tell me start with the decoding.


C#
static char [] ValidChars = { '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'J' , 'K' , 'L' , 'M' , 'N' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' }; // len=32 
const string  hashkey = "password" ; 
//key for HMAC function -- change! 
const int  codelength  = 6 ; // lenth of passcode 
string GetCodeForEmail ( string  address ) 
{ 
byte []  hash ;  
   using  ( HMACSHA1 sha1  = new  HMACSHA1 ( ASCIIEncoding . ASCII .GetBytes ( hashkey )))         hash  =  sha1 . ComputeHash ( UTF8Encoding . UTF8 . GetBytes ( address )); int  startpos  =  hash [ hash . Length - 1 ] % ( hash . Length -  codelength ); StringBuilder  passbuilder  = new StringBuilder (); for ( int  i  =  startpos ;  i  <  startpos  +  codelength ;  i ++)         passbuilder . Append ( ValidChars [ hash [ i ] % ValidChars . Length ]); return  passbuilder . ToString (); }
Posted

1) You can't. It's a hash, not an encryption algortithm - the difference is that hashes are not reversable, encryption is.

2) That's the reason people use hashes instead of encryption - to stop people like you from accessing passwords and back enginerring them.

3) Even if it was, this is a site for software professional, not wanna-be hackers.

4) Reason for my vote of one: see 1 - 3 above.
 
Share this answer
 
Comments
Karthik_Mahalingam 9-Jan-14 9:20am    
good
adriancs 9-Jan-14 9:33am    
nice +5
You can't reverse hash.
 
Share this answer
 
Comments
Yvan Rodrigues 9-Jan-14 19:57pm    
I think I did back in high school.
Assigning a password based on known information about a user?? Could you possibly come up with a more INSECURE way of generating passwords?!?!

DO NOT DO THIS!

There is NEVER a good reason to have the ability to get the original password back from any hashed or encrypted data. NEVER!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900