views:

28

answers:

3

I'm trying to seamlessly log in the user without prompting for credentials as part of a <asp:Wizard> process. My strategy is to handle the NextButtonClick event and login the user in code. I already have the user's credentials saved in session variables.

Is it possible to login a user in code? Will a hidden <asp:Login> control behind the scenes be required?

+3  A: 

If you're storing their credentials in session, I hope you are encrypting them.

But yes, if you have their credentials already, you can do:

FormsAuthentication.SetAuthCookie(username, true);

You can also run:

if(Membership.ValidateUser(username, password)) {
     FormsAuthentication.SetAuthCookie(username, true);
}

before hand to make sure that you have the correct username and password.

Jack Marchetti
I'm pretty sure anything you put into Session can be hijacked and therefore storing things like credit card information or passwords is a bad idea.
Jack Marchetti
For session security, see: http://stackoverflow.com/questions/4027023/does-sensitive-asp-net-session-data-need-to-be-encrypted
ChessWhiz
Worked perfectly. Thanks.
ChessWhiz
A: 
// This will redirect the user (check Jack Marchetti's answer for other option)
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);

This will issue the authentication ticket for the user

Y Low
+1  A: 

If you are using FormsAuthentication then just issue a session cookie:

// pass true to create a persistent cookie
FormsAuthentication.SetAuthCookie("userNameHere", true);
Dismissile