Click here to Skip to main content
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 22: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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Did you find anything? I need this encoding and decoding algorithm too.
  Permalink  
Comments
Dave Kreskowiak at 9-Jan-14 10:33am
   
Did you bother to read the answers to this?? You can NOT reverse a hash to get the orignal value from it. Besides, assigning a password based on known information only reduces the security of the system to absurd levels. Passwords should be generated randomly and not based on information that can be derived about a user.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Tadit Dash 350
2 Manas Bhardwaj 319
3 OriginalGriff 243
4 Sergey Alexandrovich Kryukov 240
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 9 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid