Keeping a user logged in

martynball

Member
Joined
Jul 8, 2014
Messages
14
Programming Experience
Beginner
Looked all over Google and can't find this. If I was to use a mysql database to store usernames and md5 passwords, I know I can compare entered data to log a user in. But how do I make the user stay logged in?

So if I was to load another form I wouldn't need to enter my login details again as the user is still logged in. I can't seem to get session variables working either :S
 
Logged into what? We can't read your mind so you need to provide all the relevant information. Do you mean a web application? If you don't want to have to implement all the plumbing yourself, use a built in membership service, which means ASP.NET Membership, Simple Membership or Identity 2.0. The latter is probably what you should use if you can, unless your needs are very basic, in which case Simple Membership may be enough.
 
Logged into what? We can't read your mind so you need to provide all the relevant information. Do you mean a web application? If you don't want to have to implement all the plumbing yourself, use a built in membership service, which means ASP.NET Membership, Simple Membership or Identity 2.0. The latter is probably what you should use if you can, unless your needs are very basic, in which case Simple Membership may be enough.

Need to keep them logged into my forms
 
Need to keep them logged into my forms

That means nothing. Web Forms? Windows Forms? Something else that you're just calling forms that aren't actually officially called forms?
 
So set a variable. When you authenticate a user, store the appropriate data in a variable and then refer to that variable when required. The appropriate data is up to you. If all you need to know is that a user has logged in then all you need is a bool. If you need to know which user is logged in then you can store the user name or ID. If you need more then you store more.

I'm not sure whether you think there is but there is no membership functionality built into Windows Forms. You either roll your own or you do what's required to get something built for ASP.NET working. I know that you can use ASP.NET Membership in Windows Forms with a bit of jiggery-pokery. I'm not sure about Simple Membership, which was actually created for ASP.NET Web Pages, or Identity 2.0. The later I would expect is possible, although I've never seen, or looked for, information on the subject.
 
So set a variable. When you authenticate a user, store the appropriate data in a variable and then refer to that variable when required. The appropriate data is up to you. If all you need to know is that a user has logged in then all you need is a bool. If you need to know which user is logged in then you can store the user name or ID. If you need more then you store more.

I'm not sure whether you think there is but there is no membership functionality built into Windows Forms. You either roll your own or you do what's required to get something built for ASP.NET working. I know that you can use ASP.NET Membership in Windows Forms with a bit of jiggery-pokery. I'm not sure about Simple Membership, which was actually created for ASP.NET Web Pages, or Identity 2.0. The later I would expect is possible, although I've never seen, or looked for, information on the subject.

But won't I loose that variable when I close the form it is created in?
 
But won't I loose that variable when I close the form it is created in?

If you declare it in the form, yes. Noone said that it has to be in a form though. Put it somewhere outside all forms so all forms have access to it.
 
Back
Top Bottom