we can give you a "ready" peace of code to you, i prefer if you dig in that to understand more about what we call : Membership management, specially if you want to do it the right way, personally i had that problem before and i was looking like you for a ready peace of code, but i realized after reading articles and documentation that there is a lot to understand about that.
So first there are many solutions you can use, one of them is Asp.Net Membership, but there are others so you need to know them and find what helps you the most, but i will talk about ASP.Net Membership little !
So what you need to understand, is to : "use technology made by professional ! instead of reinventing the wheel", avoid creating your own managing system.
Asp.Net Membership provide you what you need...
here is a link where i started :
VIDEO ON YOUTUBE[
^]
what you need to understand is that, this may be a Web Application example ! but it's a simple Database...just like any other Database and some code ! so you can use it in a winform application ! (just configure your App.Config file so it will point to the right Database : try to understand what :
Providers means what is their job)
this is an example of code you can use to check for example if a this is a use :
if (Membership.ValidateUser(tbLogin.Text, tbPassword.Text))
{
MessageBox.Show("Connected");
}
else
{
MessageBox.Show("Not Connected");
}
this.Dispose();
or this peace of code to get MembershipUser object from the User Name :
private MembershipUser GetUserMembershipFromUserName(string userName)
{
var mu = Membership.GetUser(userName);
return (mu);
}
and from that MemebershipUser Object you can get anythg you want : ID, Email, Role...etc!
you can use this peace of code in each loading of winform to keep/redirect the user !
anyway there is so much to talk about in this topic this is why i wanted you to ready more about it, sorry if my English is not very good, if you need more help let me know, good luck :)