Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a ASP.NET Login control without using a MembershipProvider?

This is an offshoot of this question.

  • How do I use a Login control if I don't have a MembershipProvider to point it at?
  • Am I understanding the use model correctly?
  • Is it even reasonable to talk about using a Login control without a MembershipProvider?
  • Dose the MembershipProvider do more than just username/password checking?
  • Would it be more reasonable to create my own MembershipProvider with the same authentication logic?

In my case, I don't need a MembershipProvider (I think) as my authentication situation is trivial (one user, one password).

I'm interested partly to "future proof" my page and partly because I'm new and wondering about how stuff works. (I tend to learn about things by running full speed into every corner case I can find :)

like image 254
BCS Avatar asked Jul 23 '09 22:07

BCS


3 Answers

You can just drop the asp:Login control in your page, then in the code behind, catch the Login Control's Authenticate event.

In the Authenticate event, check the username/password that the user has entered. The username/password are properties in the login control. (LoginCtrl.UserName, LoginCtrl.Password)

If the username/password is correct, just set the event args Authenticated property to True.

No membership provider is required.

ex. In the aspx page..

<asp:Login ID="LoginCtrl" runat="server" DestinationPageUrl="YouAreIn.aspx"></asp:Login>

In Code Behind

Private Sub Log_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles LoginCtrl.Authenticate
    If LoginCtrl.UserName = "Hello" AndAlso LoginCtrl.Password = "Hello" Then
        e.Authenticated = True
    End If

c#

void MyLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
    if(UserName == "Hello" && Password == "Hello")
        e.Authenticated = true;
}
like image 62
Justin Largey Avatar answered Nov 18 '22 21:11

Justin Largey


If you don't have a membership provider and don't really have a security system to speak of, just put two boxes on a form (user name, password) and test it in the onclick of the button.

The login control is obviously overkill for what your trying to do.

like image 35
NotMe Avatar answered Nov 18 '22 21:11

NotMe


Use Simple Forms Authentication.

like image 2
Dan Diplo Avatar answered Nov 18 '22 21:11

Dan Diplo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!