Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    I am using Visual Studio 2010 with the .aspx file extension.

    So, I am trying to use databases for a Login page.

    I know how to read the fields from a database and display them, but I am trying to figure out how to use the fields for a Login Screen and then to open a new page.
    The current code is as follows:

    <html>
    <head><title></title></head>
    <body>
    Username:
    <input id="txtUser" runat="server" type="text" /><br />
    Password:
    <input id="txtPass" runat="server" type="text" /><br />
    <input id="btnLog" type="button" value="Login" /><br />
    <p id="parData" runat="server"></p>
    </body>
    </html>


    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <script runat="server">
    Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12 .0;" + _
    "Data Source=" + Server.MapPath("Beds.accdb") + ";"
    Dim cn As New OleDbConnection(cs)
    Dim cmd As OleDbCommand
    Dim r As OleDbDataReader

    Sub Page_Load()
    cmd = New OleDbCommand("SELECT * FROM Staff;", cn)
    cn.Open()
    r = cmd.ExecuteReader()
    End Sub

    Sub btnLog_OnClick()

    Do While r.Read()

    If txtUser.Value = r("email") & txtPass.Value = r("Password") Then
    Response.Redirect("PatientList.a spx")
    Else
    parData.InnerHtml = "Incorrect credentials"
    End If
    Loop

    End Sub
    </script>


    Also, if I can get help with a log out button, that would be great.

    Thank You.
    Offline

    2
    ReputationRep:
    Does this have to be programmed in Visual Studio or are you able to choose whatever language you want?
    Offline

    10
    ReputationRep:
    (Original post by D556mm)
    I am using Visual Studio 2010 with the .aspx file extension.

    So, I am trying to use databases for a Login page.

    I know how to read the fields from a database and display them, but I am trying to figure out how to use the fields for a Login Screen and then to open a new page.
    The current code is as follows:

    <html>
    <head><title></title></head>
    <body>
    Username:
    <input id="txtUser" runat="server" type="text" /><br />
    Password:
    <input id="txtPass" runat="server" type="text" /><br />
    <input id="btnLog" type="button" value="Login" /><br />
    <p id="parData" runat="server"></p>
    </body>
    </html>


    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <script runat="server">
    Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12 .0;" + _
    "Data Source=" + Server.MapPath("Beds.accdb") + ";"
    Dim cn As New OleDbConnection(cs)
    Dim cmd As OleDbCommand
    Dim r As OleDbDataReader

    Sub Page_Load()
    cmd = New OleDbCommand("SELECT * FROM Staff;", cn)
    cn.Open()
    r = cmd.ExecuteReader()
    End Sub

    Sub btnLog_OnClick()

    Do While r.Read()

    If txtUser.Value = r("email") & txtPass.Value = r("Password") Then
    Response.Redirect("PatientList.a spx")
    Else
    parData.InnerHtml = "Incorrect credentials"
    End If
    Loop

    End Sub
    </script>


    Also, if I can get help with a log out button, that would be great.

    Thank You.
    Not too sure what language this is in, but have you got an SQL query to select the password and username from the form? I'll copy and paste my login screen from my A2 computing project, but it's in VB.NET. Hope it'll help

    Database connection

    Spoiler:
    Show
    'DB ConnectorImports System.Data.OleDb
    Public Class clsDBConnector
    Dim con As New OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim DatabasePassword As String
    Dim sql As String
    Dim da As OleDb.OleDbDataAdapter
    Dim ds As New DataSet


    Sub connect()
    dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12 .0;"
    dbSource = "Data Source = H:\Database11.accdb"
    DatabasePassword = "password"
    con.ConnectionString = dbProvider & dbSource
    con.Open()
    End Sub


    Function sqlSelect(ByVal sqlString As String)
    da = New OleDbDataAdapter(sqlString, con)
    da.Fill(ds, "Results")
    Return ds
    End Function


    Sub reset()
    ds.Reset()
    End Sub
    Sub close()
    con.Close()
    End Sub
    Function SQLselect(ByVal sqlString) 'selects table from database
    sql = sqlString
    da = New OleDb.OleDbDataAdapter(sql, con)
    da.Fill(ds, "Results")
    Return ds
    End Function


    Sub SQLinsert(ByVal sql) 'inserts data into database
    Dim da As New OleDbCommand(sql, con)
    da.ExecuteNonQuery()


    End Sub


    Sub SQLdelete(ByVal sql)
    Dim da As New OleDbCommand


    da.Connection = con
    da.CommandType = CommandType.Text
    da.CommandText = sql


    da.ExecuteNonQuery()


    End Sub


    Sub SQLupdate(ByVal sql)
    Dim da As New OleDbCommand(sql, con)
    da.ExecuteNonQuery()
    End Sub


    End Class





    Login Screen
    Spoiler:
    Show
    Public Class frmStudentlogin Dim db As New clsDBConnector
    Dim ds As New DataSet
    Private Sub frmStudentlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    db.connect()
    End Sub


    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
    Dim sql As String
    sql = "SELECT * FROM tblUsers WHERE Username = '" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"
    ds = db.sqlSelect(sql)


    'verifying user
    If ds.Tables("Results").Rows.Count = 0 Then
    MsgBox("Incorrect username/password combination, please try again")
    End If


    If ds.Tables("Results").Rows.Count > 0 Then
    lblID.Text = ds.Tables("Results").Rows(0).Ite m(0)
    MsgBox("Welcome " & txtUsername.Text)
    frmQuestion.Show()
    End If






    db.reset()
    End Sub
    End Class


    I might be able to upload the whole program to a fileshare if you need it
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Has a teacher ever helped you cheat?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Write a reply...
    Reply
    Hide
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.