Creating My Own Login System

Last post 02-03-2007 11:45 AM by pettrer. 14 replies.

Sort Posts:

  • Creating My Own Login System

    10-18-2006, 8:36 AM
    • Loading...
    • SuPerNoVi
    • Joined on 09-27-2006, 8:46 AM
    • Posts 27

    Okay I am at my wits end with this, I have trawled the internet for hours and have yet to find any answer, hopefully you guys can help me out.

    Basically I do not want to use the built in login system in ASP.NET 2.0, I have an exsisting database containing lots of customers and information and I want to be able to use this database in conjunction with a login form on ASP.NET 2.0.

    I know how to use the exsisting controls to setup a membership and roles system but I am trying to use my own database not the one Visual Studio Express sets up.

     
    Does anyone know of a guide to doing this or can direct me through the process?
     

    www.supernovi.com
  • Re: Creating My Own Login System

    10-18-2006, 10:52 AM
    • Loading...
    • stiletto
    • Joined on 07-10-2003, 8:42 AM
    • Louisville, KY
    • Posts 3,154

    You need to use custom providers for Membership and Roles to hit your tables.  Writing these are fairly easy.

    Here's a link from microsoft about the provider model and writing your own.

  • Re: Creating My Own Login System

    10-21-2006, 8:45 AM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314

    I don't want to be a nag, but I for one does not find this easy. But as there are so many links to that MSDN article, how come there's no tutorial or example code out there?

    I've tried to do this for a weeek now and honestly, my (poor) employer would rather have had me done something else... ;-)

    Please anyone... tutorial perhaps? :-)

    Pettrer 

    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Creating My Own Login System

    10-23-2006, 8:28 AM
    • Loading...
    • SuPerNoVi
    • Joined on 09-27-2006, 8:46 AM
    • Posts 27
    pettrer:

    I don't want to be a nag, but I for one does not find this easy. But as there are so many links to that MSDN article, how come there's no tutorial or example code out there?

    I've tried to do this for a weeek now and honestly, my (poor) employer would rather have had me done something else... ;-)

    Please anyone... tutorial perhaps? :-)

    Pettrer 



    Well I am happy to show you what I have achieved thus far.

    This is the VB code for my Login.aspx and so far the Login page does communicate and authenticate with the database.

    I am now currently working on expanding on this. 

     

    1    <script language="VB" runat="server">
    2 Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
    3
    4 End Function
    5
    6 'Sub doLogin(ByVal Source As Object, ByVal E As EventArgs)
    7 ' If ValidateUser(txtUID.Text, txtPWD.Text) = True Then
    8 ' FormsAuthentication.RedirectFromLoginPage(txtUID.Text, False)
    9 ' Else
    10 ' lblError.Visible = "True"
    11 ' lblError.text = "We're sorry, but the information you provided " & _
    12 ' "does not match our database. Please try again."
    13 ' ValidateUser.Text = ""
    14 ' End If
    15 'End Sub
    16 17 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    18 If Page.IsPostBack Then
    19
    20
    21 Dim
    sText As String
    22 Dim
    blnValidUser
    23 Dim sUser, sPwd As String
    24 25 Dim
    sFirst, sName, sLast As String
    26 Dim
    strConn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\A2Z.mdf;Integrated Security=True;User Instance=True" 27 Dim MySQL As String = "Select [Name], [Login], " & _
    28 "[Password] from Login " & _
    29 "Where Login=@uid AND Password=@Pwd" 30 Dim MyConn As New Data.SqlClient.SqlConnection(strConn)
    31 Dim objDR As Data.SqlClient.SqlDataReader
    32 Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, MyConn)
    33 Cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@Uid", txtUID.Text))
    34 Cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@Pwd", txtPWD.Text))
    35 MyConn.Open()
    36
    37
    38
    39 Try 40 objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    41 While objDR.Read()
    42
    43 sUser = objDR("login")
    44 sPwd = objDR("Password")
    45 sName = objDR("Name")
    46 Response.Write(sName)
    47 End While
    48 49 If
    sFirst = "" And sLast = "" Then 50 blnValidUser = "False" 51 Else 52 blnValidUser = "True" 53 Session("Name") = sName
    54 End If
    55 Catch
    ex As Exception
    56 lblError.Visible = "true" 57 lblError.Text = "Sorry Errors have occurred" 58 End Try
    59 End If
    60 End Sub
    61 </script>

    Here is the change I made to the Web.config

          <authentication mode="Forms">
    <forms name="myWebPageCookie" loginUrl="login.aspx" timeout="30">
    </forms>
    </authentication>

    <authorization>
    <allow users="?" />
    <deny users="*" />
    </authorization>
    I hope this helps you in any way, I will give you my full solution once I have done it.
    www.supernovi.com
  • Re: Creating My Own Login System

    10-23-2006, 9:21 AM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314

    Thank you so much!

    I don't know if it's of any interest to you or if you've already done it, but here's a link to my login page code:

    http://forums.asp.net/thread/1431652.aspx 

    Now I'll try to mix it with your loggedin page! 

    all the best,

    Pettrer

    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Creating My Own Login System

    10-24-2006, 1:03 PM
    • Loading...
    • sfbarron
    • Joined on 10-04-2006, 5:03 PM
    • South Jersey
    • Posts 16

    Hey, will this code work with the LoginName & LoginStatus controls?  Create User / Change password / Forgot password I assume would all have to be custom implemented??  Also, are your passwords hashed in your database or just a plain string?

    Thanks,

    Steve

  • Re: Creating My Own Login System

    10-30-2006, 5:50 AM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314

    Hi again Steve,

    I hope all is well with you and that your code starts to come through. The code I had only works with the login control but I imagine configuring the other controls wouldn't be too hard (if one knew what properties they encompass, that is), so you are assuming correctly. Note that I have only tried the Create User Wizard apart from the Login control. Also, my pwds are in plain text for now. I think there is a property somewhere telling whether to encrypt it or not.

    Best,

    Pettrer

    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Creating My Own Login System

    10-31-2006, 5:14 PM
    • Loading...
    • DLester01
    • Joined on 10-06-2003, 5:55 AM
    • Posts 32

    I downloaded the Provider Toolkit from he link below and it has the code for the SQLMembership provider that Microsoft released.  I have just written on based on this for Oracle although I have not tested it yet with the login controls.  This should speed up your development some what.

    http://msdn2.microsoft.com/en-us/asp.net/aa336558.aspx

    Regards

  • Re: Creating My Own Login System

    01-25-2007, 6:53 AM
    • Loading...
    • SuPerNoVi
    • Joined on 09-27-2006, 8:46 AM
    • Posts 27

    It has been a while since I have visited these waters, mainly because of the lack of actual help on these forums.

    However I have scrapped my initial idea completely and started working on a different way of doing a login and register system.

    It is proving difficult but I will share my solution when I get it. Maybe in the next ASP.Net release Microsoft might actually make an effort to create customizable login controls that can be configured to use SQL databases.
     

    www.supernovi.com
  • Re: Creating My Own Login System

    01-27-2007, 11:48 AM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314
    Hi a
    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Creating My Own Login System

    01-27-2007, 11:52 AM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314

    Hi again,

    I skipped the built-in login functionality and developed my own, session-based thing. Since then, I have realised that it's very easy to use "win forms", so that's what I'm doing on my latest project. Give it a try if you haven't done that yet!

    Pettrer

    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Creating My Own Login System

    01-27-2007, 12:14 PM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314

    Hmmm, maybe win forms is not what I meant but simply forms. Here's a link: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/security/formsauth.aspx

    P

    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Creating My Own Login System

    01-31-2007, 6:32 AM
    • Loading...
    • SuPerNoVi
    • Joined on 09-27-2006, 8:46 AM
    • Posts 27

    Does anyone understand how asp.net automatically knows your login status with the asp.net login status control?

    I would like to know the same about how the login control works automatically. The thing is I need to override these functions and make them work connecting to my own sql database and not the one created by the site administration.

     Any help greatly appreciated, this is annoying the hell out of me.
     

    www.supernovi.com
  • Re: Creating My Own Login System

    01-31-2007, 6:34 AM
    • Loading...
    • SuPerNoVi
    • Joined on 09-27-2006, 8:46 AM
    • Posts 27

    Does anyone understand how asp.net automatically knows your login status with the asp.net login status control?

    I would like to know the same about how the login control works automatically. The thing is I need to override these functions and make them work connecting to my own sql database and not the one created by the site administration.

     Any help greatly appreciated, this is annoying the hell out of me.
     

    www.supernovi.com
  • Re: Creating My Own Login System

    02-03-2007, 11:45 AM
    • Loading...
    • pettrer
    • Joined on 02-08-2006, 4:08 AM
    • Stockholm, Sweden
    • Posts 314

    Hi,

    Perhaps using forms, even though one can't watch it. Check my link on that matter (forms) - it works like a charm for the system I built. :-)

    Pettrer

    Coding is a nine-to-five job: Nine PM to Five AM.
Page 1 of 1 (15 items)
<