Click here to Skip to main content
15,887,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I'm having a problem here with registration to ms access database.
The error im having is this "Syntax Error in INSERT INTO statement"
i checked the code but i cannot find out what is the problem.


The column names are correct. Connection to database file is okay too. Where i make mistake?
Thanks

What I have tried:

VB
<pre>Public Sub RegisterUser()
        Try
            With cmd
                .Connection = conn
                .CommandText = "INSERT INTO Users (user,pass,admin) VALUES (@user,@pass,0)"
                .Parameters.AddWithValue("@user", Login.txtUsername.Text)
                .Parameters.AddWithValue("@pass", Login.txtPassword.Text)
                .ExecuteNonQuery()
                Result = .ExecuteNonQuery
                .Parameters.Clear()
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            If Result > 0 Then
                MessageBox.Show("Sign Up Successful", "Warehouse Tool", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Login.txtUsername.Text = ""
                Login.txtPassword.Text = ""
                Login.txtUsername.Focus()
            Else
                MessageBox.Show("Failed to register user!", "Warehouse Tool", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Login.txtUsername.Text = ""
                Login.txtPassword.Text = ""
                Login.txtUsername.Focus()
            End If
            cmd.Dispose()
            If conn IsNot Nothing Then
                conn.Close()
            End If
        End Try
    End Sub
Posted
Updated 31-May-20 4:55am

"User" is an access reserved word, and you shouldn't use it as a column name. If you do, you have to escape the name:
SQL
INSERT INTO Users (`user`, pass, admin) ...


But ... you have a more serious problem: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
 
Share this answer
 
Comments
diablo22 31-May-20 10:23am    
You were right i total forgot about the "reserved name" thank you very much, also i sow another problem that i execute 2 times the code so i fix this too now.
About the password protection i didn't understand from the link how to do it.

If you could better explane me how to do it would appriciate it. Thank you.
OriginalGriff 31-May-20 10:33am    
Follow the link and read it: it includes the code and it's pretty much as basic as it can get, short of me coming round and typing it in for you ...
VB
Public Shared Function EncryptPassword(password As String) As String
        'Simple Encryption
        'Dim PasswordBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(password)
        'Dim EncryptedPassword As String = Convert.ToBase64String(PasswordBytes)
        'Return EncryptedPassword

        'SHA1 Encryption
        Dim sha1 As New SHA1CryptoServiceProvider()
        Dim PasswordBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(password)
        Dim EncryptedPassword As String = System.Text.Encoding.UTF8.GetString(sha1.ComputeHash(PasswordBytes))
        Return EncryptedPassword

        'MD5 Encryption
        'Dim md5 As New MD5CryptoServiceProvider
        'Dim PasswordBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(password)
        'Dim EncryptedPassword As String = System.Text.Encoding.UTF8.GetString(md5.ComputeHash(PasswordBytes))
        'Return EncryptedPassword

    End Function
 
Share this answer
 
Comments
Richard MacCutchan 31-May-20 11:09am    
That is not encryption, it is hashing; you should change the method name.
diablo22 31-May-20 11:22am    
i found this and used it with little edit anad the 3 options password is protected in database so if someone will need it can check it out too thats why i leave it.

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