Solved

ASP Net -  How does Login Control Authenticate users behind the scenes?

Posted on 2007-11-15
2
1,095 Views
Last Modified: 2013-11-07
Hi,

Here's my problem.  I've been asked to develop a cut down mobile version of our companies site.  The existing company site uses in built asp.net 2.0 Membership provider.  The login for the existing site is completely out of the box.  ie.  The authenticating of the user credentials is handled behind the scenes by the Login control.

The problem is that I have to mirror this functionality in the mobile login form and there is no login control for mobile forms.  So I guess I need to understand how the Login control on the existing site handles the encryption of user credentials so I can write my own logic for the mobile login.

Hope that makes sense.  Can anyone point me in the write direction?

0
Comment
Question by:fizzer666
  • 2
2 Comments
 
LVL 10

Expert Comment

by:Dxpert
ID: 20288800
Hey, I think that you can basically create a Custom Membership Provider like the one here:
http://www.15seconds.com/issue/050216.htm

Then have a login/logout procedure on your form that will validate the user. I am using something like this on my own website, except that I use Forms Authentication:

.ASPX

<asp:Panel ID="pnlLogin" runat=server Visible=true>
      <asp:Label ID="lblPassword" CssClass="textBlack12px" Text="What's my name?" runat=server />
      <asp:TextBox Id="txtPassword" width="100" TextMode="Password" runat="server"/><br />
      <asp:Button Id="cmdLogin1" Text="Login" UseSubmitBehavior=true runat="server" />
</asp:Panel>
<div class="textRed12px" id="ErrorMessage" runat="server" />


.ASPX.VB

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

      'on this example, If the user is logged in, I change the Login text to Logout...
      'note that I'm only using a Password field
        If User.Identity.IsAuthenticated Then
            SetLogin(True)
        End If
      
        If Page.IsPostBack Then
            If cmdLogin1.Text = "Login" Then
                ProcessLoginNew()
            Else
                SignOutNew()
            End If
        End If

    End Sub

    Sub SetLogin(ByVal bLoggedIn As Boolean)

        lblPassword.Visible = Not bLoggedIn
        txtPassword.Visible = Not bLoggedIn

        If bLoggedIn Then
            cmdLogin1.Text = "Logout"
        Else
            cmdLogin1.Text = "Login"
        End If
       
    End Sub
       
    Sub ProcessLoginNew()
   
          'in here you would call your Membership.ValidateUser
          
        If txtPassword.Text.Trim.Length > 0 Then
            If FormsAuthentication.Authenticate("user", txtPassword.Text.ToLower) Then
                FormsAuthentication.RedirectFromLoginPage("user", True)
                ErrorMessage.InnerHtml = ""
                SetLogin(True)
            Else
                ErrorMessage.InnerHtml = "Invalid Password."
            End If
        End If
    End Sub
   
    Sub SignOutNew()
        FormsAuthentication.SignOut()
        SetLogin(False)
    End Sub



Some more info:
http://aspnet.4guysfromrolla.com/articles/120705-1.aspx

Hope this helps you get started...
0
 
LVL 10

Accepted Solution

by:
Dxpert earned 500 total points
ID: 20288860
     If Membership.ValidateUser(Login1.UserName, Login1.Password) Then
            FormsAuthentication.RedirectFromLoginPage(Login1.UserName, False)
        End If

http://forums.asp.net/t/950427.aspx

;-)

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question