Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...
I want a perfect login logint code for my website..

But I don't want to use Asp.net login control.
I want to manually code for login logout...

please help me.
Posted
Comments
Prasad_Kulkarni 4-May-12 4:14am    
What you've tried so far?

You need a standard TextBox, a TextBox set to retrieve password characters and you need to use the MembershipProvider to validate the user details. The method you want to use is ValidateUser.
 
Share this answer
 
for the login try the following code


C#
if (Membership.ValidateUser(UserName.Text, Password.Text))
                {
                    FormsAuthentication.SetAuthCookie(UserName.Text, RememberMe.Checked);
}
                else
                {
                    MembershipUser user = Membership.GetUser(UserName.Text);

                    if (user == null)
                    {
                        LoginError.Text =
                            string.Format(Resources.Generic.USERS_ERROR_NOUSER, UserName.Text);
                    }
                    else
                    {
                        if (!user.IsApproved)
                        {
                            LoginError.Text = Resources.Generic.USERS_ERROR_NOT_APPROVED;
                        }
                        else if (user.IsLockedOut)
                        {
                            LoginError.Text = Resources.Generic.USERS_ERROR_LOCKED_OUT;
                        }
                        else
                        {
                            LoginError.Text = Resources.Generic.USERS_ERROR_GENERIC;
                        }
                    }
                }

Where UserName and Password are the textboxs containing the username and password.

Meanwhile for logout try

C#
FormsAuthentication.SignOut();


Cheers
 
Share this answer
 
I have custom login logout code in these 2 projects. go ahead and check the out. you can in fact find full functionality working here

YaBlogEngine - A Tiny Blog Engine written in ASP.NET/C#[^]

YaMessaging - A simple e-mail like messaging application[^]
 
Share this answer
 

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