Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello, I am making a login form that saves your username and password to a text file (encrypted) like this:

xhsdg495 (username) - jasjdhfb (password)

When I try to decrypt it I get an error saying it can't reconize some characters in the Base64. My question is: How can I remove the (space)-(space) so that the program knows what the username and password is?
Posted

1 solution

There are a couple of things here:
Normally, you would use String.Split, but there is no overload which splits on a string, so the direct answer is to use the Regex.Split function:

C#
string myString = "xhsdg495 - jasjdhfb";
string[] parts =  Regex.Split(myString," - ");

parts[0] is "xhsdg495" and parts[1] is "jasjdhfb"

But it is not good practice to store encrypted passwords anyway: store a MD5 or (prefereably) SHA hash instead. Since these are non-reversible functions, you cannot get back to the password from the stored value. You then generate the same hash of the entered password when they log in, and compare the two values. It is also recommended that the user name is included in the data when you hash it to prevent the same value being generated by the same password used by two different users.
 
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