0

how to create cookies in windows forms using c#? or is there any way to save data "LIKE" cookies.

I want to save username and password in client machine so is there any other way to save

Thanks

Veerendra K
  • 2,145
  • 7
  • 32
  • 61

2 Answers2

0

i want to save username and password in client machine

If you set the password form type to "password" the client browser should do all the work for you here. When they log in it asks if they want to save these credentials for the web site.

*EDIT: If all you are looking to do is write a cookie using c#, the answer was only a quick google search away... http://msdn.microsoft.com/en-us/library/aa287547(v=vs.71).aspx

Buchannon
  • 1,671
  • 16
  • 28
0

Cookies are for websites, not Windows forms. But ultimately, cookies are just files that are dropped on the client machine that can be read and updated as you require. In which case, you could just drop and read files using System.IO.StreamWriter and System.IO.StreamReader. Something like this:

var writer = new System.IO.StreamWriter("MyFilename.txt");
writer.WriteLine("some text here");
writer.Close();

And to read the file:

var reader = new System.IO.StreamReader("MyFilename.txt");
var fileContents = reader.ReadToEnd();
reader.Close()
Crwydryn
  • 840
  • 6
  • 13
  • Saving passwords in a txt file with no encryption at all? I don't think so. – Arian Motamedi Apr 30 '13 at 19:47
  • The question was how to implement cookie-like functionality in a windows form environment, not how to encrypt data. If he is familiar with writing cookies in a web environment then one would hope that he is already familiar with the pitfalls of storing unencrypted passwords. Password integrity is clearly something that should be heavily considered in this sort of situation, but was not part of the original scope of the question. – Crwydryn Apr 30 '13 at 19:57
  • "i want to save username and password in client machine". He specifically mentions that he needs to figure out a way to store user-sensitive data. – Arian Motamedi Apr 30 '13 at 19:59
  • But he also implies that he is already familiar with storing cookies in a web environment - just apply whatever encryption method he uses there, to this. This is simply a way to store the data in a cookie-like fashion, which answers the main question "how to create cookies in windows forms using c#?"; what data you stick in there is up to you. – Crwydryn Apr 30 '13 at 20:04
  • By the way. I'm not arguing for the sake of it. I understand your point entirely. I just think How to store, and How to encrypt are two separate questions. – Crwydryn Apr 30 '13 at 20:06
  • Ok, Is there any encryption method to encrypt password. I mean just encrypt the password and save into txt file and one more thing is how to read data separately, i mean how to read username and password separately from single txt file.I know little bit there are concepts like stringtokenizer or iostream readers or something else.Can you plz tell how to do this. thanks – Veerendra K May 01 '13 at 10:45
  • [this]( http://stackoverflow.com/questions/202011/encrypt-decrypt-string-in-net) should point you in the right direction regarding encryption. And to access the values independently you should investigate using a Key Value Pair approach, as shown [here]( http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx) – Crwydryn May 01 '13 at 18:25