Im doing a registration and login form where I already encrypted the password when user entered the password in registration phase. So for login I know that I need to compare the encrypted password in database with the newly entered encrypted password during login. I dont know if im missing some code or im writing the wrong code. I know that this question have been asked few times but I hope I can get some help here. The error that im getting is just a message where Failed to Connect to Database
I already found the solution C# encrypted Login and try to follow the code but still, it have error.
If PasswordTextBox1.Text = "" Or UsernameTextBox2.Text = "" Then
MessageBox.Show("Please fill-up all fields!", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'Clear all fields
PasswordTextBox1.Text = ""
UsernameTextBox2.Text = ""
'Focus on Username field
UsernameTextBox2.Focus()
Else
'Connect to DB
Dim conn As New System.Data.OleDb.OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "C:\Users\user1\Documents\Visual Studio 2010\Projects\Crypto\Crypto\crypto.accdb"
Try
'Open Database Connection
conn.Open()
Dim sql As String = "SELECT Password FROM registration WHERE Username='" & Encrypt(UsernameTextBox2.Text) & "'"
Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
Dim sqlRead As OleDbDataReader = cmd.ExecuteReader()
Dim password As String = cmd.ExecuteScalar().ToString().Replace("", "")
If (password = Encrypt(PasswordTextBox1.Text)) Then
PasswordTextBox1.Clear()
UsernameTextBox2.Clear()
'Focus on Username field
UsernameTextBox2.Focus()
Me.Hide()
Mainpage.Show()
Else
LoginAttempts = LoginAttempts + 1
If LoginAttempts >= 3 Then
End
Else
' If user enter wrong username or password
MessageBox.Show("Sorry, wrong username or password", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Error)
'Clear all fields
PasswordTextBox1.Text = ""
UsernameTextBox2.Text = ""
'Focus on Username field
UsernameTextBox2.Focus()
End If
End If
Catch ex As Exception
MessageBox.Show("Failed to connect to Database", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'Clear all fields
PasswordTextBox1.Text = ""
UsernameTextBox2.Text = ""
End Try
End If
End Sub
I expecting that the encrypted password in database can be matched with the newly entered password so that user can login into the system.