Solved

VB .NET Login Screen Help

Posted on 2003-11-20
9
1,008 Views
Last Modified: 2012-08-13
I have been trying to make a login screen for a program I have, but have not been successful and don't really even know if I am doing it right.  I have most of the program written but mainly don't know how to validate the information I am retrieving for the userid and password.  

This is an example of the file the userid and password would be included.
8 char userid and 11 char password

hartmar letmein    
kc123456vbnetboo  
mm234567dcmetro    

Any other suggestions with problems would also be greatly appreciated.

Imports System.IO

Public Class frmLogin
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtUser As System.Windows.Forms.TextBox
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents btnSubmit As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtUser = New System.Windows.Forms.TextBox
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.btnSubmit = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "User-ID:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Password:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtUser
        '
        Me.txtUser.Location = New System.Drawing.Point(88, 8)
        Me.txtUser.Name = "txtUser"
        Me.txtUser.Size = New System.Drawing.Size(120, 20)
        Me.txtUser.TabIndex = 2
        Me.txtUser.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.Location = New System.Drawing.Point(88, 40)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.Size = New System.Drawing.Size(120, 20)
        Me.txtPassword.TabIndex = 3
        Me.txtPassword.Text = ""
        '
        'btnSubmit
        '
        Me.btnSubmit.Location = New System.Drawing.Point(24, 72)
        Me.btnSubmit.Name = "btnSubmit"
        Me.btnSubmit.Size = New System.Drawing.Size(80, 32)
        Me.btnSubmit.TabIndex = 4
        Me.btnSubmit.Text = "Submit"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(120, 72)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(80, 32)
        Me.btnClear.TabIndex = 5
        Me.btnClear.Text = "Clear"
        '
        'frmLogin
        '
        Me.AcceptButton = Me.btnSubmit
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(224, 110)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.btnSubmit)
        Me.Controls.Add(Me.txtPassword)
        Me.Controls.Add(Me.txtUser)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmLogin"
        Me.Text = "Login Screen"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private datNames As StreamReader
    Private datInfo As StreamWriter
    Private myString As String

    Public Sub EventsForm1_Load(ByVal sender As Object, _
           ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            datNames = New StreamReader("c:\vb\appdata.dat")
        Catch
            MessageBox.Show("File does not exist!")

        End Try
    End Sub

    Private Structure sLogin

        Dim strUser As String
        Dim strPassword As String

    End Structure
    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim frmSplashScreenInstance As New frmSplashScreen
        Dim lngLength As Long
        Dim loginNum As Integer
        Dim strLogin As String
        Dim ServiceData() As sLogin
        Dim intIndex As Integer
        datInfo = New StreamWriter("c:\vb\logfile.dat")
        loginNum = 0
        strLogin = datNames.ReadLine


        If txtUser.Text = "" Or lngLength > 8 Or lngLength < 6 Then
            MessageBox.Show("User-ID must be maximum of 8 Characters and Minimum of 6")
            With txtUser
                .SelectionStart = 0
                .SelectionLength = lngLength
                .Focus()
            End With
        End If

        If txtPassword.Text = "" Or lngLength > 11 Then
            MessageBox.Show("Password must be Maximum of 11 Characters")
            With txtPassword
                .SelectionStart = 0
                .SelectionLength = lngLength
                .Focus()
            End With
        End If

        If loginNum < 3 Then
            Do Until datNames.Peek = -1
                ReDim Preserve ServiceData(intIndex)
                strLogin = datNames.ReadLine

                With ServiceData(intIndex)
                    .strUser = strLogin.Substring(0, 8)
                    .strPassword = strLogin.Substring(9, 11)
                End With

                intIndex += 1 'increment the index

            Loop

 *******  If userId & password Then
                datInfo.WriteLine(txtUser.Text & Now.Month & "/" & Now.DayOfYear & "/" & Now.Year & " " & Now.ToLocalTime & "Successful")
                frmSplashScreenInstance.Show()
                Me.Dispose()

            End If

********If userId & password !=  Then
                MessageBox.Show("Invalid User-ID or Password! Please Try Again.")
                loginNum += 1  ' increment the login number
                HighlightText()
                datInfo.WriteLine(txtUser.Text & Now.Month & "/" & Now.DayOfYear & "/" & Now.Year & Now.ToLocalTime & "Unsuccessful")
            End If

        ElseIf loginNum >= 3 Then
            MessageBox.Show("Invalid Account: Program Terminated")
            Me.Close()
        End If
    End Sub

    Private Sub HighlightText()
        With txtUser
            .BackColor = Color.Red
            .Font = New System.Drawing.Font(txtUser.Font, FontStyle.Bold)
        End With
        With txtPassword
            .BackColor = Color.Red
            .Font = New System.Drawing.Font(txtPassword.Font, FontStyle.Bold)
        End With
    End Sub
End Class
0
Comment
Question by:brassmon
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:malharone
ID: 9791831
this is a full source application that has login into a sql server using web services.
http://windowsforms.net/Default.aspx?tabindex=7&tabid=44
0
 
LVL 9

Expert Comment

by:malharone
ID: 9791964
hope this helps ... i modified your code

Imports System.IO

Public Class frmLogin
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtUser As System.Windows.Forms.TextBox
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents btnSubmit As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtUser = New System.Windows.Forms.TextBox()
        Me.txtPassword = New System.Windows.Forms.TextBox()
        Me.btnSubmit = New System.Windows.Forms.Button()
        Me.btnClear = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "User-ID:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Password:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtUser
        '
        Me.txtUser.Location = New System.Drawing.Point(88, 8)
        Me.txtUser.Name = "txtUser"
        Me.txtUser.Size = New System.Drawing.Size(120, 20)
        Me.txtUser.TabIndex = 2
        Me.txtUser.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.Location = New System.Drawing.Point(88, 40)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.Size = New System.Drawing.Size(120, 20)
        Me.txtPassword.TabIndex = 3
        Me.txtPassword.Text = ""
        '
        'btnSubmit
        '
        Me.btnSubmit.Location = New System.Drawing.Point(24, 72)
        Me.btnSubmit.Name = "btnSubmit"
        Me.btnSubmit.Size = New System.Drawing.Size(80, 32)
        Me.btnSubmit.TabIndex = 4
        Me.btnSubmit.Text = "Submit"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(120, 72)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(80, 32)
        Me.btnClear.TabIndex = 5
        Me.btnClear.Text = "Clear"
        '
        'frmLogin
        '
        Me.AcceptButton = Me.btnSubmit
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(224, 110)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.btnSubmit)
        Me.Controls.Add(Me.txtPassword)
        Me.Controls.Add(Me.txtUser)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmLogin"
        Me.Text = "Login Screen"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private datNames As StreamReader
    Private datInfo As StreamWriter
    Private myString As String

    Dim arlUsers As New ArrayList()

    Public Sub loadLoginInfo()
        Try
            datNames = New StreamReader("C:\Documents and Settings\Owner\Desktop\logininfo.txt")
            Dim st As String
            While datNames.Peek <> -1
                st = datNames.ReadLine()
                If Not (st Is Nothing OrElse st.Trim.Length < 1) Then
                    Me.arlUsers.Add(New LoginInfo(st))
                End If
            End While
        Catch ex As Exception
            MessageBox.Show("File does not exist! or the following error occured: " & ex.Message)
        Finally
            Try
                datNames.Close()
            Catch ex As Exception

            End Try
        End Try
    End Sub
    Public Sub EventsForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadLoginInfo()
    End Sub

    Private Function validateLogin() As LoginInfo
        Dim er As String = ""
        Dim uname As String = Trim(txtUser.Text)
        Dim password As String = Trim(txtPassword.Text)

        If uname Is Nothing OrElse uname.Length < 6 OrElse uname.Length > 8 Then
            er += " - Invalid Username"
        End If

        If password Is Nothing OrElse password.Length < 6 OrElse password.Length > 8 Then
            er += " - Invalid Password"
        End If

        If er.Length > 0 Then
            Return Nothing
        Else
            Dim li As LoginInfo
            For Each li In Me.arlUsers
                If li.matches(uname, password, True) Then
                    Return li
                End If
            Next
            Return Nothing
        End If
    End Function

    Private numTimesClicked As Short = 0

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim loginInfo = validateLogin()
        If loginInfo Is Nothing Then
            numTimesClicked += 1
            If numTimesClicked >= 3 Then
                MessageBox.Show("Can no longer login - 3 bad logins", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.btnSubmit.Enabled = False
            End If
        Else
            MessageBox.Show("Successful")
        End If
    End Sub

    Private Sub HighlightText()
        With txtUser
            .BackColor = Color.Red
            .Font = New System.Drawing.Font(txtUser.Font, FontStyle.Bold)
        End With
        With txtPassword
            .BackColor = Color.Red
            .Font = New System.Drawing.Font(txtPassword.Font, FontStyle.Bold)
        End With
    End Sub

    Public Class LoginInfo
        Private uName As String
        Private password As String
        Public Sub New(ByVal loginName As String, ByVal password As String)
            Me.uName = uName
            Me.password = password
        End Sub

        Public Function matches(ByVal uNameToMatch As String, ByVal passwordToMatch As String, Optional ByVal ignoreCase As Boolean = True) As Boolean
            Return (String.Compare(uNameToMatch, uName, ignoreCase) = 0) AndAlso (String.Compare(passwordToMatch, password, ignoreCase) = 0)
        End Function

        Public Sub New(ByVal singleLine As String)
            If singleLine Is Nothing OrElse singleLine.Trim.Length < 1 Then
                Throw New Exception("Invalid input string")
            Else
                Dim temp As Short = singleLine.IndexOfAny(" ")
                uName = Trim(singleLine.Substring(0, temp))
                password = Trim(singleLine.Substring(temp))
                'MessageBox.Show("USER:[" & uName & "] Password:[" & password & "]")
            End If
        End Sub
    End Class
End Class
0
 

Author Comment

by:brassmon
ID: 9795219
malharone:

thanks for your help, I can now login, but with the code you wrote any time I have a invalid userid or password the program crashes.  This is what the error says:

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an object.


It then Points a green arrow and highlights frmLogin where it says Public Class frmLogin

Any ideas?
0
 

Author Comment

by:brassmon
ID: 9795307
I believe the line:
If loginInfo Is Nothing Then
is the problem?  because if they entered data then it crashes?  but i don't know what to write if that is the problem.

Also...  Another problem I am having is writing information to a file.  These are the lines I am using, but they don't do anything except create the file.  No Information is written inside the file.
 
Private datInfo As StreamWriter
datInfo = New StreamWriter("c:\vb\logfile.dat")
datInfo.WriteLine(txtUser.Text & "Unsuccessful")
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:malharone
ID: 9798475
ok .. let me just fix it now..
0
 
LVL 9

Expert Comment

by:malharone
ID: 9798938
how about now ... this will keep the log also



Imports System.IO

Public Class frmLogin
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtUser As System.Windows.Forms.TextBox
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents btnSubmit As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtUser = New System.Windows.Forms.TextBox()
        Me.txtPassword = New System.Windows.Forms.TextBox()
        Me.btnSubmit = New System.Windows.Forms.Button()
        Me.btnClear = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "User-ID:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Password:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtUser
        '
        Me.txtUser.Location = New System.Drawing.Point(88, 8)
        Me.txtUser.Name = "txtUser"
        Me.txtUser.Size = New System.Drawing.Size(120, 20)
        Me.txtUser.TabIndex = 2
        Me.txtUser.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.Location = New System.Drawing.Point(88, 40)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(120, 20)
        Me.txtPassword.TabIndex = 3
        Me.txtPassword.Text = ""
        '
        'btnSubmit
        '
        Me.btnSubmit.Location = New System.Drawing.Point(24, 72)
        Me.btnSubmit.Name = "btnSubmit"
        Me.btnSubmit.Size = New System.Drawing.Size(80, 32)
        Me.btnSubmit.TabIndex = 4
        Me.btnSubmit.Text = "Submit"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(120, 72)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(80, 32)
        Me.btnClear.TabIndex = 5
        Me.btnClear.Text = "Clear"
        '
        'frmLogin
        '
        Me.AcceptButton = Me.btnSubmit
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(224, 110)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnClear, Me.btnSubmit, Me.txtPassword, Me.txtUser, Me.Label2, Me.Label1})
        Me.Name = "frmLogin"
        Me.Text = "Login Screen"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private datNames As StreamReader
    Private datInfo As StreamWriter
    Private myString As String

    Dim arlUsers As New ArrayList()

    Public Sub loadLoginInfo()
        Try
            datNames = New StreamReader("C:\Documents and Settings\Owner\Desktop\logininfo.txt")
            Dim st As String
            While datNames.Peek <> -1
                st = datNames.ReadLine()
                If Not (st Is Nothing OrElse st.Trim.Length < 1) Then
                    Me.arlUsers.Add(New LoginInfo(st))
                End If
            End While
        Catch ex As Exception
            MessageBox.Show("File does not exist! or the following error occured: " & ex.Message)
        Finally
            Try
                datNames.Close()
            Catch ex As Exception

            End Try
        End Try
    End Sub
    Public Sub EventsForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadLoginInfo()
    End Sub

    Private Function validateLogin() As LoginInfo
        Dim er As String = ""
        Dim uname As String = Trim(txtUser.Text)
        Dim password As String = Trim(txtPassword.Text)

        If uname Is Nothing OrElse uname.Length < 6 OrElse uname.Length > 8 Then
            er += " - Invalid Username"
        End If

        If password Is Nothing OrElse password.Length < 6 OrElse password.Length > 8 Then
            er += " - Invalid Password"
        End If

        If er.Length > 0 Then
            Return Nothing
        Else
            Dim li As LoginInfo
            For Each li In Me.arlUsers
                If li.matches(uname, password, True) Then
                    Return li
                End If
            Next
            Return Nothing
        End If
    End Function

    Private numTimesClicked As Short = 0


    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim loginInfo As LoginInfo = validateLogin()
        Dim logData As New System.IO.StreamWriter("c:\logfile.dat", True)

        If loginInfo Is Nothing Then
            numTimesClicked += 1
            If numTimesClicked >= 3 Then
                MessageBox.Show("Can no longer login - 3 bad logins", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.btnSubmit.Enabled = False
            End If
            logData.WriteLine(txtUser.Text & Format(Date.Today, "MM/dd/yyyy") & " " & Now.ToLocalTime & " Unsuccessful")
            logData.Close()
            MsgBox("bad login")
        Else
            MessageBox.Show("Successful")
            logData.WriteLine(loginInfo.uName & " " & Format(Date.Today, "MM/dd/yyyy") & " " & Now.ToLocalTime & " Successful")
            logData.Close()
        End If
    End Sub

    Private Sub HighlightText()
        With txtUser
            .BackColor = Color.Red
            .Font = New System.Drawing.Font(txtUser.Font, FontStyle.Bold)
        End With
        With txtPassword
            .BackColor = Color.Red
            .Font = New System.Drawing.Font(txtPassword.Font, FontStyle.Bold)
        End With
    End Sub

    Public Class LoginInfo
        Public uName As String
        Private password As String
        Public Sub New(ByVal loginName As String, ByVal password As String)
            Me.uName = uName
            Me.password = password
        End Sub

        Public Function matches(ByVal uNameToMatch As String, ByVal passwordToMatch As String, Optional ByVal ignoreCase As Boolean = True) As Boolean
            Return (String.Compare(uNameToMatch, uName, ignoreCase) = 0) AndAlso (String.Compare(passwordToMatch, password, ignoreCase) = 0)
        End Function

        Public Sub New(ByVal singleLine As String)
            If singleLine Is Nothing OrElse singleLine.Trim.Length < 1 Then
                Throw New Exception("Invalid input string")
            Else
                Dim temp As Short = singleLine.IndexOfAny(" ")
                uName = Trim(singleLine.Substring(0, temp))
                password = Trim(singleLine.Substring(temp))
            End If
        End Sub
    End Class
End Class
0
 
LVL 27

Expert Comment

by:planocz
ID: 9799001
Hi brassmon,
Check this link out for more info on logins....
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20787103.html
0
 

Author Comment

by:brassmon
ID: 9803529
Malharone:  I believe I have two more problems and then should be set.  

When the user successfully logs in I want to load another form, frmSplashScreen, and also unload the frmLogin from memory.  Could you help me with that?

Also I had added this code, but when the login was incorrect it still loaded frmSplashScreen, can you help me to fix that as well...  I really appreciate your help, you will get the points of course.

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim loginInfo As LoginInfo = validateLogin()
        Dim logData As New System.IO.StreamWriter("c:\logfile.dat", True)
        Dim frmSplashScreenInstance As New frmSplashScreen
        Dim frmLoginInstance As New frmLogin
        If loginInfo Is Nothing Then
            numTimesClicked += 1
            If numTimesClicked >= 3 Then
                MessageBox.Show("Can not Login: 3 Bad Logins", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.btnSubmit.Enabled = False
            Else
                Return
            End If
            logData.WriteLine(txtUser.Text & " " & Now.ToLocalTime & " Unsuccessful")
            MsgBox("Unsuccessful Login: Please enter User Name and Password.")


        Else
            MessageBox.Show("Successful Login.", "Loading Splash Screen....")
            logData.WriteLine(loginInfo.uName & " " & Now.ToLocalTime & " Successful")
            logData.Close()
******frmSplashScreenInstance.Show()
        End If
    End Sub
0
 
LVL 9

Accepted Solution

by:
malharone earned 500 total points
ID: 9811907


    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim loginInfo As LoginInfo = validateLogin()
        Dim logData As New System.IO.StreamWriter("c:\logfile.dat", True)
        Dim frmSplashScreenInstance As New frmSplashScreen
        Dim frmLoginInstance As New frmLogin
        If loginInfo Is Nothing Then
            numTimesClicked += 1
            If numTimesClicked >= 3 Then
                MessageBox.Show("Can not Login: 3 Bad Logins", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.btnSubmit.Enabled = False
            Else
                Return
            End If
            logData.WriteLine(txtUser.Text & " " & Now.ToLocalTime & " Unsuccessful")
            MsgBox("Unsuccessful Login: Please enter User Name and Password.")


        Else
            MessageBox.Show("Successful Login.", "Loading Splash Screen....")
            logData.WriteLine(loginInfo.uName & " " & Now.ToLocalTime & " Successful")
            logData.Close()
            dim frmSplashScreenInstance as new frmSplashScreen()
            me.hide()
            frmSplashScreenInstance.showDialog()
        End If
    End Sub


since your project's startup object is frmLogin, unloading frmLogin after frmSplashScreenInstance is displayed, will close the program. assume login is successful in the following cases
case1:
after login
frmSplashScreenInstance.show
frmLogin.close
result: your app'll close .. you wont see the frmSplashScreenInstance

case 2
after login
frmSplashScreenInstance.showDialog
frmLogin.close
result: frmLogin will be closed after frmSplashScreenInstance is closed ... so frmLogin will still reside in the memory until frmSplashScreenInstance is not closed

i'd recommend you just hide the frmLogin before calling the showDialog.

if you really want your frmLogin to be removed from the memory then do this...
have your project's startup object be SUB MAIN ... in your sub main, check and see if the login's successful ... if it is then close the frmLogin and display frmSplashScreenInstance
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now