Results 1 to 7 of 7

Thread: Login system using database Help needed

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Exclamation Login system using database Help needed

    My login system used a database1.mdf and if the user is new to the program it will have a default login, if signed in with the default login then user will be promoted to a firstrun.vb screen which will allow the them to change username and password or else it will go to the mainmenu.

    Problem : I am unsure how to stop the firstrun form from appearing if the user as already changed the password or username, either 1. and what code to add to the form firstrun.vb if they would like to change it, meaning updating the database.mdf.

    Anymore information if needed please qoute me.

    Code:
     Imports System.Data.SqlClient
    Public Class Login
        Dim cm As SqlConnection
        Dim dr As SqlDataReader
        Dim cmd As SqlCommand
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim dr1 As SqlDataReader
            Dim cmd1 As SqlCommand
            Dim Username As String
            Dim Password As String
    
            cm = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Login.mdf;Integrated Security=True;User Instance=True")
            cm.Open()
    
            cmd = New SqlCommand("SELECT Username FROM UserPass", cm)
    
            dr = cmd.ExecuteReader
    
            dr.Read()
    
            Username = dr(0)
            cm.Close()
            cm.Open()
            cmd = New SqlCommand("SELECT Password FROM UserPass", cm)
            dr = cmd.ExecuteReader
    
            dr.Read()
    
            Password = dr(0)
    
    
            If Password = "Default" And Username = "Default" Then
                Me.Hide()
                FirstRun.Show()
            End If
    
    
            If Username <> "Default" Or Password <> "Default" Then
                MsgBox("Incorrect Login", MsgBoxStyle.Exclamation)
            ElseIf Password <> "Default" And Username <> "Default" Then
    
            End If
    
    
        End Sub

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Login system using database Help needed

    Try something like this:

    If it is the first time something is being run the UserName is Default and the password is Default right? So
    the user enters the username 'Default' and a Password of Default

    If Me.userName.Text.ToUpper() = 'DEFAULT' AndAlso Me.passWord.Text.ToUpper () = 'DEFAULT' Then
    Me.Hide()
    FirstRun.Show()
    Else
    strSQL = "Select Count(*) FROM UserPass Where UserName = @uName And password = @pWord"
    cmd.Text = strSQL
    cmd.Parameters.AddWithValue('@uName',Me.userName.Text)
    cmd.Parameters.AddWithValue('@pWord',Me.passWord.Text)
    End
    Now execute your reader.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Re: Login system using database Help needed

    Quote Originally Posted by GaryMazzone View Post
    Try something like this:

    If it is the first time something is being run the UserName is Default and the password is Default right? So
    the user enters the username 'Default' and a Password of Default

    If Me.userName.Text.ToUpper() = 'DEFAULT' AndAlso Me.passWord.Text.ToUpper () = 'DEFAULT' Then
    Me.Hide()
    FirstRun.Show()
    Else
    strSQL = "Select Count(*) FROM UserPass Where UserName = @uName And password = @pWord"
    cmd.Text = strSQL
    cmd.Parameters.AddWithValue('@uName',Me.userName.Text)
    cmd.Parameters.AddWithValue('@pWord',Me.passWord.Text)
    End
    Now execute your reader.
    what is the cmd.parameters.addwithvalue for?
    Also Me.userName.Text.ToUpper() what does that do? please explain.

    thanks

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Re: Login system using database Help needed

    bump

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Re: Login system using database Help needed

    Any1?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Login system using database Help needed

    Please don't keep bumping your thread every hour or two. Please don't bump your threads at all, as it's against forum rules. We all volunteer our time here if and when we can and we are all over the world, in different time zones. We will get to your question if and when we can. There's no justification for bumping a thread that is still on the first page of the forum because your question is no more important than everyone else's that you're trying to leapfrog. If it slips off the first page, then you need to ask yourself why and think about rephrasing the question or adding new information.

    Anyway, Parameters.AddWithValue does just as the name suggests: it adds to the Parameters collection with a value, i.e. it creates a parameter with the specified name and the specified value and adds it to the commands collection of parameters. Of course, the documentation could have told you that. For more information on how and why you use parameters, follow the Blog link in my signature and check out my post on ADO.NET Parameters.

    You might also like to follow the CodeBank link in my signature and check out my WinForms Login thread, which I believe provides the cleanest way to login to a WinForms application.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Re: Login system using database Help needed

    hi

    The add is taking the values users enters and adding them to strSQL ie @uName and @pWord to form the query thats passed to database

    ToUpper means uppercase ie Default would be come DEFAULT

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width