Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi im new here just want to seek some help on my project i need my log in form to accept only what the users registered credentials and yes they can login using there credentials but the thing is even if the password is on uppercase letters the user can access it by only using lowercase letter please help TIA

What I have tried:

heres my code

VB
Imports MySql.Data.MySqlClient

Public Class Login
    Private Sub Login_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        End
    End Sub
    Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtuser.Select()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
        Try
            DbOpen()
            Dim query = "Select * from login where Username= '" & txtuser.Text & "' AND Password = '" & txtpass.Text & "'"
            Dim cm As New MySqlCommand(query, cn)
            Dim reader = cm.ExecuteReader
            If reader.Read Then
                'login success

                Dim role = reader("Userlevel").ToString
                Dim name = reader("Name").ToString
                reader.Close()
                If role = "ADMIN" Then

                    Audit(role, name, "Login Success")
                    MsgBox("Welcome Admin", vbInformation, "System Message.")
                    Me.Dispose()


                    Panels.ShowDialog()

                    txtuser.Clear()
                    txtpass.Clear()
                    role = ""
                ElseIf role = "STAFF" Then
                    Audit(role, name, "Views the menu")
                    MsgBox("Welcome Staff!", vbInformation, "System Message.")
                    Me.Dispose()



                    staff.ShowDialog()

                    txtuser.Clear()
                    txtpass.Clear()
                    role = ""




                End If
            Else
                'login failed
                MsgBox("Invalid Password! Try Again.", vbInformation, "System Message")
                txtuser.Clear()
                txtpass.Clear()
            End If
            txtuser.Select()
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            DbClose()
        End Try
        ' POS.Timer1.Start()
        'POS.lbltime.Text = Date.Now.ToString("hh:mm:ss tt")
        'POS.lbldate.Text = Date.Now.ToString("MM/dd/yyyy")


    End Sub
Posted
Updated 25-Jan-20 11:07am
v3

Don't do like this. Never ever concatenate values directly to an SQL statament. It leaves you open to SQL injection. Instead, use MySqlParameter Class[^]

Another thing that never must be done, don't store the password as plain text in the database. To do this correctly, see Password Storage: How to do it.[^]. This also fixes the problem you have.
 
Share this answer
 
Comments
Marky Angel Kevin Garcia 25-Jan-20 12:26pm    
thank you for your help sir
Wendelius 25-Jan-20 12:35pm    
You're welcome
First point, do not use string concatenation to create SQL statements, it leaves your system vulnerable to SQL injection. Use parameterised queries always.

Second point, do not store passwords in clear text, use salted hash values always. See Secure Password Authentication Explained Simply[^]

Third point, passwords should match exactly, so if uppercase letters are part of it, they must still be uppercase to login.
 
Share this answer
 
Comments
Marky Angel Kevin Garcia 25-Jan-20 12:26pm    
thank you for your help sir
VB
query = "Select * from login where Username= '" & txtuser.Text & "' AND Password = '" & txtpass.Text & "'"

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900