Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys can anyone tell me how can i store the User Id and password globely to show the user name in each form in window application..

thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 20-Mar-12 3:00am    
I did read you question. You have a page full of confusions. You need to add a tag "Forms".
--SA
Sergey Alexandrovich Kryukov 20-Mar-12 3:08am    
So, please see my answer.
--SA

First, you should never store a password anywhere, ever. This is unsafe. Authentication never needs a password. Isn't this obvious? A hint: you can use a cryptographic hash function, please see:
http://en.wikipedia.org/wiki/Cryptographic_hash_function[^].

Compare hash with a hash, never an original form of a password. Nobody should ever know it except the owner of it, the user.

Now, don't use MD5 or SHA-1 algorithms; they are unsafe. For example, use one from SHA-2 family. Please see:
http://en.wikipedia.org/wiki/Md5[^],
http://en.wikipedia.org/wiki/SHA-1[^],
http://en.wikipedia.org/wiki/SHA-2[^].

They are well implemented in .NET, please see:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx[^].

Now, where to store it and the user names? There are no a concept of "global" in .NET (thanks goodness! finally!). You can use the singleton pattern, please see:
http://en.wikipedia.org/wiki/Singleton_pattern[^].

A correct .NET implementation is shown here:
http://csharpindepth.com/Articles/General/Singleton.aspx[^].

—SA
 
Share this answer
 
Comments
Sushil Mate 20-Mar-12 3:13am    
your comment made me laugh.. my five
Sergey Alexandrovich Kryukov 20-Mar-12 3:27am    
Thank you, Sushil.
Excuse me, which comment?
--SA
Sushil Mate 20-Mar-12 5:00am    
Your welcome!
His question & your comment "page full of confusions". someone used this phrase for me when i started my coding..
Anyways i found your solution very informative.
Sergey Alexandrovich Kryukov 20-Mar-12 13:11pm    
Than you very much...
--SA
Hehe...are you using a database? or just to make things simple write them to a file then read them when you want. Stream Writer and Stream Reader
 
Share this answer
 
store in session and set the session time out more an more in web.config file.becuase the session value you can access in each and every form
 
Share this answer
 
Comments
Rajendra Koranga 20-Mar-12 1:21am    
Hi sir , i have already written above that i m working with window application .net window application so i cant use the cookies and session...thanks

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