How to keep variables value alive even after login in Login_Authenticate function?

31 Views Asked by At

I am using below given code to get email, username and password value from the login control in asp.net c# project. But what happens is when authenticate happens all the data vanishes from the variables email, uname and pass. I have need of these three variables in further programming. How can i keep this information persistent, even after login.

protected void myLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
        // Get the email address entered
        TextBox EmailTextBox = myLogin.FindControl("Email") as TextBox;
        string email = EmailTextBox.Text.Trim();
        TextBox UserNameTextBox = myLogin.FindControl("UserName") as TextBox;
        string uname = UserNameTextBox.Text.Trim();
        TextBox PasswordTextBox = myLogin.FindControl("Password") as TextBox;
        string pass = PasswordTextBox.Text.Trim();
        Label1.Text = uname;
        Label2.Text = pass;
        //Label2.Text = myLogin.UserName.ToString();
        
        // Verify that the username/password pair is valid
        if (Membership.ValidateUser(myLogin.UserName, myLogin.Password))
        {
            // Username/password are valid, check email
            MembershipUser usrInfo = Membership.GetUser(myLogin.UserName);
            if (usrInfo != null && string.Compare(usrInfo.Email, email, true) == 0)
            {
                // Email matches, the credentials are valid
                e.Authenticated = true;
            }
            else
            {
                // Email address is invalid...
                e.Authenticated = false;
                
            }
        }
        else
        {
            // Username/password are not valid...
            e.Authenticated = false;
        }
    }
0

There are 0 best solutions below