Password match problem

Oct 29 2009 2:41 AM
I am developing a windows application, my database is in MS-Access, i have the user details form which will store all the users detail as well as create the username and the password for login to the application. It is working all right but i have used 2 textboxes, 1 for password and the other one for confirmpassword. I want that the password and the confirmpassword should be same. But it is not happening. Now the user can feed 2 passwords. But actually this should not happen. Please help me out how to do it. The coding for the user details form is: private void btnadd_Click(object sender, EventArgs e) { pageAction = "ADD"; ClearFields(); SetEditState(true); txtusrname.Focus(); } private void btnsave_Click(object sender, EventArgs e) { try { ConnectionClass l_ConnectionClass = new ConnectionClass(); userId = l_ConnectionClass.generateIDnew("select max(userId) from [tbluserlogin]"); userName = txtusrname.Text.ToString(); userPwd = txtpwd.Text; userConPwd = txtconfirmpwd.Text; string logouttime = DateTime.MinValue.ToString(); users = l_ConnectionClass.checkuser(userName); if (users > 0) { MessageBox.Show("username already exists."); } else { l_ConnectionClass.SaveAddUser(userId, userName, userStatus, userRole, userPwd, userConPwd, logouttime); LoadGrid(); ClearFields(); txtusrname.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btndelete_Click(object sender, EventArgs e) { try { ConnectionClass l_ConnectionClass = new ConnectionClass(); if (MessageBox.Show("You want to delete it.", "User Details", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { l_ConnectionClass.DeleteAddUser(userId); ClearFields(); LoadGrid(); } else { return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btncancel_Click(object sender, EventArgs e) { LoadGrid(); SetEditState(false); } private void btnclose_Click(object sender, EventArgs e) { this.Close(); } private void dgvuserlogin_SelectionChanged(object sender, EventArgs e) { try { if (dgvuserlogin.SelectedRows.Count > 0) { userId = Convert.ToInt32(dgvuserlogin.CurrentRow.Cells["userId"].Value); PublicVariables.OSUserID = Convert.ToInt32(dgvuserlogin.CurrentRow.Cells["userId"].Value); userName = Convert.ToString(dgvuserlogin.CurrentRow.Cells["userName"].Value); userStatus = Convert.ToInt32(dgvuserlogin.CurrentRow.Cells["userStatus"].Value); string _userRole = dgvuserlogin.CurrentRow.Cells["userRole"].Value.ToString(); if (_userRole == "Admin") { rbtnadmin.Checked = true; } else { rbtnadmin.Checked = false; } if (_userRole == "Normal") { rbtnnormal.Checked = true; } else { rbtnnormal.Checked = false; } if (_userRole == "Display") { rbtndisplay.Checked = true; } else { rbtndisplay.Checked = false; } userPwd = Convert.ToString(dgvuserlogin.CurrentRow.Cells["userPwd"].Value); userConPwd = Convert.ToString(dgvuserlogin.CurrentRow.Cells["userConPwd"].Value); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } Please help with the changes in the coding

Answers (2)

0
Nilanka Dharmadasa

Nilanka Dharmadasa

  • 0
  • 3k
  • 0
Oct 29 2009 5:22 AM

You can check the passwords and ask the user to re enter them if they are not matching.
 

private void btnsave_Click(object sender, EventArgs e)
{
try
{
ConnectionClass l_ConnectionClass =
new ConnectionClass();
userId = l_ConnectionClass.generateIDnew(
"select max(userId) from [tbluserlogin]");
userName = txtusrname.Text.ToString();
string userPwd = txtpwd.Text;
string userConPwd = txtconfirmpwd.Text;
string logouttime = DateTime.MinValue.ToString();
users = l_ConnectionClass.checkuser(userName);
if (users > 0)
{
MessageBox.Show(
"username already exists.");
}
//If the password and confirmed passwrd are not same, a message box pops up and asks the user to reenter them.
else if(!userPwd.Equals(userConPwd))
{
MessageBox.Show(
"Passwords given in two places are not matching. Please re enter.");
}
else
{
l_ConnectionClass.SaveAddUser(userId, userName, userStatus, userRole, userPwd, userConPwd, logouttime);
LoadGrid();
ClearFields();
txtusrname.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

Is this what you wanted to know??
0
jinge

jinge

  • 0
  • 1.5k
  • 42.4k
Oct 29 2009 3:57 AM
I've already answered your question. What's the problem? If you still can not figure it out. Please send your project to me.