Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Visual basic login

Options
  • 11-05-2013 7:20pm
    #1
    Registered Users Posts: 227 ✭✭


    Hi guys,
    I'm having a bit of trouble here. I'll give ye a bit of info first...

    I'm trying to create a login system, that can be used for members of the website, and admins.

    The data is stored in access. 2 tables, Musicians and Admins. With 3 columns in each...MusicianID, MusicianEmail, and Musician Password, with the same 3 appropriately named ones for Admins.

    They will all be logging in using their email and passwords, so I need SQL to search for those. But when I search for an email address, how do I search for the matching password, and not just search all the passwords in the table? I'll also need to know this for when I get on to storing cookies and ill be using their IDs.

    Here is my code so far. As you can see, im a novice at this.....



    Imports
    System.Data.OleDb

    Public


    Class Login



    Inherits System.Web.UI.Page



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



    End Sub



    Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles emailaddresstextbox.TextChanged



    End Sub

     

     



    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click



    Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:\VBproject\MusicWebsite.accdb")



    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Musicians WHERE MusicianEmail = '" & emailaddresstextbox.Text & "' AND MusicianPassword = '" & passwordtextbox.Text & "' ", con)



    Dim cmd1 As OleDbCommand = New OleDbCommand("SELECT * FROM Admins WHERE AdminEmail = '" & emailaddresstextbox.Text & "' AND AdminPassword = '" & passwordtextbox.Text & "' ", con)

    con.Open()



    Dim sdr As OleDbDataReader = cmd.ExecuteReader()



    If (sdr.Read() = True) Then

    MessageBox.Show(

    "You have successfully logged in!")



    Dim mainForm As New mainForm

    mainForm.Show()



    Me.Hide()


    Else

    MessageBox.Show(

    "Invalid username or password!")



    End If



    End Sub



    Private Sub adminlogin()

     



    Dim sdr As OleDbDataReader = cmd.ExecuteReader()

     



    If (sdr.Read() = True) Then

    MessageBox.Show(

    "The user is valid!")



    Dim mainForm As New MainForm

    mainForm.Show()



    Me.Hide()



    Else

    MessageBox.Show(

    "Invalid username or password!")



    End If



    End Sub



    Private Sub userlogin()



    End Sub

     



    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click



    Me.Close()



    End Sub



    Protected Sub PasswordRecovery1_SendingMail(sender As Object, e As MailMessageEventArgs) Handles PasswordRecovery1.SendingMail



    End Sub

    End

    Class

    I don't know why the formatting is a bit weird, sorry.

    When I run it I get a compilation error saying
    "Compiler Error Message: BC30451: 'MessageBox' is not declared. It may be inaccessible due to its protection level
    The other errors are:
    -cmd (same as above) not declared etc
    -Type MainForm not defined
    -'Hide' is not a member of 'Login'
    -'Close' is not a member of 'Login'

    Any help appreciated. I know they are probably small stupid mistakes :o


Comments

  • Moderators, Category Moderators, Entertainment Moderators, Sports Moderators Posts: 22,584 CMod ✭✭✭✭Steve


    Google ASP.net user login. ASP manages all of this so you don't need to worry about it and you can write whatever backend code you need for the cool stuff in VB. :)


  • Registered Users Posts: 2,145 ✭✭✭dazberry


    You appear to be trying to mix a web application with a win forms (desktop) application. You need to code for one or the other, not both...

    D.


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    DON'T STORE PASSWORDS IN YOUR DATABASE, instead encrypt the password and see if the encrypted password matches?


  • Registered Users Posts: 2,858 ✭✭✭Duckjob


    A message box telling the user their login was successful makes no sense in the context of a web app.

    In any case, the native VB.NET msgbox won't work in ASP.NET anywhere outside of a VS hosted environment. If you really wanted you could use AJAX toolkit or similar for popups, but there's really no point. Just redirect user on successful login to the authenticated page.

    As mentioned, look up ASP.NET authentication as it does all this for you - bouncing user to login page if not logged in, redirecting back on successful login etc.

    edit: All your code looks like Windows forms code, not ASP.NET :confused:


  • Registered Users Posts: 227 ✭✭TheHopeful


    Ok guys ive been doing a lot of work on it since and its 95% working now.
    Slight problem with hashing the passwords though. I used the following:




    Dim passCommand As New OleDbConnection(cmd2, connection)

    Dim password As String = passCommand.ExecuteScalar().ToString()

    If password = FormsAuthentication.HashPasswordForStoringInConfigFile(passwordtextbox.Text, "SHA1") Then
    ......etc


    So it seems that method is obsolete now, any quick fix that i can just stick directly in instead without having to restructure my code and write a lot more code?
    Thanks.


  • Advertisement
Advertisement