naren5050
Posts: 2
|
Posted: 07/26/2006, 6:47 AM |
|
Hello,
I wish to allow users to update their own profile. For this, I need to compare the password in the database (OrgPassword) with the password they type (OldPassword). Only if the two match, the NewPassword will be accepted and the profile (along with the NewPassword) will be updated.
I created one Hidden control (OrgPassword) and two textboxes (input=password) named as OldPassword and NewPassword.
I am able to get the value of the OrgPassword from the database, as well as the values from OldPassword and NewPassword controls. I can even correctly update the NewPassword in the database. However, I am not able to compare the OrgPassword with the OldPassword. Irrespective of the OldPassword, the NewPassword gets updated.
Here is my code (I have modified the "OrgPassword Required Validation" code to the following):
//OrgPassword Validation @7-43BB97B9
{
Control cntrl = (Control)e.getSource();
// cntrl.addError("Message: The Org Password is " + cntrl.getValue() );
// cntrl.addError("Message: The Old Password is " + e.getComponent().getControl("OldPassword").getValue() );
// cntrl.addError("Message: The New Password is " + e.getComponent().getControl("NewPassword").getValue() );
if (((String)cntrl.getValue()).equals ((String)(e.getComponent().getControl("OldPassword").getValue()))) {
cntrl.addError("The Old Password is wrong! Please retry.");
}
}
//End OrgPassword Validation
I also tried following options, but none works:
1) if ((String)cntrl.getValue() == ((String)(e.getComponent().getControl("OldPassword").getValue())
2) if ((String)cntrl.getValue() != ((String)(e.getComponent().getControl("OldPassword").getValue())
3) if (cntrl.getValue() == (e.getComponent().getControl("OldPassword").getValue())
4) if (cntrl.getValue() != (e.getComponent().getControl("OldPassword").getValue())
5) if (cntrl.getValue() == (e.getComponent().getControl("OldPassword").getValue()) {} else {...}
6) if (cntrl.getValue() != (e.getComponent().getControl("OldPassword").getValue()) {} else {...}
Please help.
Thanks.
|
|
|
matheus
Posts: 386
|
Posted: 07/26/2006, 7:33 AM |
|
if (!String.valueOf(e.getControl().getValue()).equals(String.valueOf(e.getComponent().getControl("OldPassword").getValue()))){
// IT'S DIFFERENT
}
The question is, comparison in Object cannot use == or != , need use equals or something like this. And to do your comparison is good cast all to String.
_________________
Matheus Trevizan
Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br |
|
|
naren5050
Posts: 2
|
Posted: 07/30/2006, 7:18 AM |
|
Quote matheus:
if (!String.valueOf(e.getControl().getValue()).equals(String.valueOf(e.getComponent().getControl("OldPassword").getValue()))){
// IT'S DIFFERENT
}
Thanks a lot matheus for your solution.
It worked without me having to change anything!!... saving me of the lot of trouble.
Best regards,
|
|
|
|