Login User
-
:)Hallo everybody,,,! Please anybody if can help me...! I have problem with my login user code .., If the user type the wrong password the messagebox couldn't appear "Pasword does not match with username", but the messagebox appeared is "Username does not exist" asa same as we type the wrong username. THe code is written below :
Dim ds As New DataSet Dim dt As DataTable Dim dr As DataRow Dim username As String = Me.txtUserName.Text Dim password As String = Me.txtPassword.Text Dim strSql As String = "SELECT * FROM users where username='" + username + "' and password='" + password + "'" Dim oleConn As New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;Data Source=data\persedkont.mdb") Dim oleDa As New OleDb.OleDbDataAdapter(strSql, oleConn) oleDa.Fill(ds) dt = ds.Tables(0) If (dt.Rows.Count = 0) Then MessageBox.Show(username + " does not exists!", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Else dr = dt.Rows(0) Dim pass As String = dr(2).ToString Dim userId As String = dr(1).ToString If (dt.Rows.Count = 0) And password <> pass Then MessageBox.Show("Password does not match with username.", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.clearForm() Else If password = pass Then Me.clearForm() Me.Close() End If End If End If 'MessageBox.Show(strSql) Try Catch ex As Exception MessageBox.Show("Wrong UserId or Password") End Try
Thank's verymuch for help. Best Regards, Ahmad Rifai Yusuf -
:)Hallo everybody,,,! Please anybody if can help me...! I have problem with my login user code .., If the user type the wrong password the messagebox couldn't appear "Pasword does not match with username", but the messagebox appeared is "Username does not exist" asa same as we type the wrong username. THe code is written below :
Dim ds As New DataSet Dim dt As DataTable Dim dr As DataRow Dim username As String = Me.txtUserName.Text Dim password As String = Me.txtPassword.Text Dim strSql As String = "SELECT * FROM users where username='" + username + "' and password='" + password + "'" Dim oleConn As New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;Data Source=data\persedkont.mdb") Dim oleDa As New OleDb.OleDbDataAdapter(strSql, oleConn) oleDa.Fill(ds) dt = ds.Tables(0) If (dt.Rows.Count = 0) Then MessageBox.Show(username + " does not exists!", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Else dr = dt.Rows(0) Dim pass As String = dr(2).ToString Dim userId As String = dr(1).ToString If (dt.Rows.Count = 0) And password <> pass Then MessageBox.Show("Password does not match with username.", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.clearForm() Else If password = pass Then Me.clearForm() Me.Close() End If End If End If 'MessageBox.Show(strSql) Try Catch ex As Exception MessageBox.Show("Wrong UserId or Password") End Try
Thank's verymuch for help. Best Regards, Ahmad Rifai Yusufhi man i dont know, u can make a select statement to select justonly the password of the entered user name, and then compare it with the entered password ..... if doesnt match give the message box with a sentence u want ...... Thanks alot Hamody
-
:)Hallo everybody,,,! Please anybody if can help me...! I have problem with my login user code .., If the user type the wrong password the messagebox couldn't appear "Pasword does not match with username", but the messagebox appeared is "Username does not exist" asa same as we type the wrong username. THe code is written below :
Dim ds As New DataSet Dim dt As DataTable Dim dr As DataRow Dim username As String = Me.txtUserName.Text Dim password As String = Me.txtPassword.Text Dim strSql As String = "SELECT * FROM users where username='" + username + "' and password='" + password + "'" Dim oleConn As New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;Data Source=data\persedkont.mdb") Dim oleDa As New OleDb.OleDbDataAdapter(strSql, oleConn) oleDa.Fill(ds) dt = ds.Tables(0) If (dt.Rows.Count = 0) Then MessageBox.Show(username + " does not exists!", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Else dr = dt.Rows(0) Dim pass As String = dr(2).ToString Dim userId As String = dr(1).ToString If (dt.Rows.Count = 0) And password <> pass Then MessageBox.Show("Password does not match with username.", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.clearForm() Else If password = pass Then Me.clearForm() Me.Close() End If End If End If 'MessageBox.Show(strSql) Try Catch ex As Exception MessageBox.Show("Wrong UserId or Password") End Try
Thank's verymuch for help. Best Regards, Ahmad Rifai YusufHAve u checked whether the table has any rows in it because the Message box should pop only when the table rows are 0 and also when you are executing the fill method of dataadpater also aspecify the TAble name and use the table insted of index while retrieving the populated table I think this should answer all your queries Mandar Patankar MCP
-
:)Hallo everybody,,,! Please anybody if can help me...! I have problem with my login user code .., If the user type the wrong password the messagebox couldn't appear "Pasword does not match with username", but the messagebox appeared is "Username does not exist" asa same as we type the wrong username. THe code is written below :
Dim ds As New DataSet Dim dt As DataTable Dim dr As DataRow Dim username As String = Me.txtUserName.Text Dim password As String = Me.txtPassword.Text Dim strSql As String = "SELECT * FROM users where username='" + username + "' and password='" + password + "'" Dim oleConn As New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;Data Source=data\persedkont.mdb") Dim oleDa As New OleDb.OleDbDataAdapter(strSql, oleConn) oleDa.Fill(ds) dt = ds.Tables(0) If (dt.Rows.Count = 0) Then MessageBox.Show(username + " does not exists!", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Else dr = dt.Rows(0) Dim pass As String = dr(2).ToString Dim userId As String = dr(1).ToString If (dt.Rows.Count = 0) And password <> pass Then MessageBox.Show("Password does not match with username.", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.clearForm() Else If password = pass Then Me.clearForm() Me.Close() End If End If End If 'MessageBox.Show(strSql) Try Catch ex As Exception MessageBox.Show("Wrong UserId or Password") End Try
Thank's verymuch for help. Best Regards, Ahmad Rifai YusufHi, I wanna help you handling... so for username adn password i will show u my idea (maybe easy one) If me.txtUserName.Text<>"john" Then msgbox("the user " & me.txtUserName.Text & "doesnt exist") ElseIf me.txtPasswor.Text<>"kenedy" Then msgbox("password incorrect") EndIf this is a simple code for username and password for login without using DB