string emailfield=txtEmail.Text.ToString();
string url =
"http://localhost:3076/user/Authenticate-Users.aspx?email="+emailfield;
I want to encrypt the querystring and then decrpyt. Is there any way to do this in C#?
Thanks
string emailfield=txtEmail.Text.ToString();
string url =
"http://localhost:3076/user/Authenticate-Users.aspx?email="+emailfield;
I want to encrypt the querystring and then decrpyt. Is there any way to do this in C#?
Thanks
You can encrypt a name/value collection to a string, and then just pass that encrypted string as a single query argument.
I demonstrate this technique in an article, Encrypting Query Arguments.
Since encrypted data will most likely contain special characters it must be base64-encoded or similar.
You can find a encode / decode class that does the dirty work for you. Many of them out there. Here is one example.
Possibly looking for Server.UrlEncode?
The URLEncode method applies URL encoding rules, including escape characters, to a specified string.
(Just in case you were too specific with "encrypt", otherwise others have good answers regarding protecting the string's value.)
A simpler solution could be to store a GUID along with the user account when it is created. You could call it VerificationCode
, for example. When you create the user account, you randomly store a GUID with it, 120a9c10-4f2e-11e0-b8af-0800200c9a66 for example.
Now, in the activation link, you embed the GUID instead of the email address:
http://localhost:3076/user/Authenticate-Users.aspx?code=120a9c10-4f2e-11e0-b8af-0800200c9a66
When the page executes, it looks up the user by the GUID to mark that the account has been confirmed.