Click here to Skip to main content
11,479,170 members (64,800 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# C#4.0
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.


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 26-Nov-12 23:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
KARTHIK Bangalore at 9-Jan-14 9:20am
   
good
adriancs at 9-Jan-14 9:33am
   
nice +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can't reverse hash.
  Permalink  
Comments
Yvan Rodrigues at 9-Jan-14 19:57pm
   
I think I did back in high school.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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!
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 215
1 F-ES Sitecore 195
2 OriginalGriff 165
3 Frankie-C 120
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,366
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 13 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100