Results 1 to 4 of 4

Thread: login script for ASP

  1. #1
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default login script for ASP

    right ive at my witts end!

    Does anyone have or can show me the right direction...
    I need a login script using ASP that will select a user from a MySQL database based upon the username and password they enter into a form. Then it will write their details to a cookie.

    Thats something fairly simple- but you would be shocked at how hard it is to find this on google!

    any help would be massivley appricated!
    Why does ASP have to exisit?! why cant everything be PHP?!

  2. #2
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    352
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default

    I love ASP (altough PHP is nice too.)

    This some code i used some years go for a website. It doenst use cookies, but sessions instead. Won't be to hard to change the script and use cookies (or both).

    Code:
    <%
    If Request.Form("btnLogin") = "Login" AND Request.Form("txtName") <> AND Request.Form("txtPassword") <> "" Then
        '-- Declare your variables
        Dim objDBConn, cmdDC, RecordSet
        Dim RecordToEdit, Updated, strUserName, strPassword
     Dim strUserIP 
     
     strUserName = Request.Form("txtName")
     strUserName = Replace(strUserName,"\","\\")
     strUserName = Replace(strUserName,"'","\'")
     strPassword = Request.Form("txtPassword")
     strPassword = Replace(strPassword,"\","\\")
     strPassword = Replace(strPassword,"'","\'")
    
     Session("userName") = strUserName
        '-- Create object and open database
        Set objDBConn = Server.CreateObject("ADODB.Connection")
        objDBConn.Open "Driver={MySQL ODBC 3.51 Driver}; Server=server_name; Database=db_name; UID=user_name; PWD=password"
     strUserIP = Request.ServerVariables("REMOTE_ADDR")
     strSQL = "SELECT ip FROM ip_ban WHERE ip = '" & strUserIP & "'"
     Set rs = objDBConn.Execute(strSQL)
     If Not rs.EOF then
      Session("UserAuth") = "ban"
     End If
     Set rs = Nothing
        Set cmdDC = Server.CreateObject("ADODB.Command")
        cmdDC.ActiveConnection = objDBConn
        '-- default SQL
        SQL = "SELECT * FROM members"
        If Request.Form("txtName") <> "" Then 
      SQL = "SELECT members.* FROM members " & _
            " WHERE members.userID ='" & strUserName & _
            "' AND members.password ='" & strPassword & ";"
        End If
        cmdDC.CommandText = SQL
        Set RecordSet = Server.CreateObject("ADODB.Recordset")
        '-- Cursor Type, Lock Type
        '-- ForwardOnly 0 - ReadOnly 1
        '-- KeySet 1 - Pessimistic 2
        '-- Dynamic 2 - Optimistic 3
        '-- Static 3 - BatchOptimistic 4
        RecordSet.Open cmdDC, , 0, 2
    
     If Not RecordSet.EOF Then
        Dim struserLevel
        struserLevel = RecordSet.Fields("userLevel")
        Session("userLevel") = struserLevel
     Else
        'The user was not validated...
        'Take them to a page which tells them they were not validated...
         Response.redirect "/?error=logon_nok"
     End If
    End If
     
    'Close some stuff, to prevent errors
    Set cmdDC = Nothing
    Set RecordSet = Nothing
    '
    If Session("userLevel") = "member" AND Session("userName") <> "" OR Session("userLevel") = "admin" AND Session("userName") <> "" Then
    'Content goes here
    Else
     Response.redirect "/?error=logon_nok"
    End If
    %>
    It uses a database table called members, with the following fields: userID, password, userLevel, UserAuth (= IP the users IP adres).

    Hope it helps moving in the right direction
    Last edited by Rappie; 19th March 2008 at 05:57 PM. Reason: way too many typo's

  3. #3
    Join Date
    Jan 2008
    Location
    Copenhagen
    Posts
    42
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    remember...

    PHP is a scripting language, not a programing language!

    so, stop loving bad languages!

    Bruno Alexandre
    Strøby, Danmark

    "a Portuguese in Denmark"

  4. #4
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    ASP is a scripting langauge too
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. looking for image controlled asp script
    By HostCan in forum ASP (VBScript)
    Replies: 2
    Last Post: 25th July 2007, 05:56 PM
  2. Webmail Login
    By askjim in forum Technical Support
    Replies: 2
    Last Post: 16th April 2007, 11:54 PM
  3. webmail login
    By amac10 in forum ASP.NET
    Replies: 1
    Last Post: 27th June 2006, 04:52 PM
  4. ASP Server Side Mail script
    By Wise Webs in forum ASP (VBScript)
    Replies: 16
    Last Post: 11th January 2006, 09:39 PM
  5. PHPMyAdmin login
    By slippers in forum Technical Support
    Replies: 3
    Last Post: 28th November 2005, 03:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •