0

I tried various ways as per my knowledge:

updatePassword(dataForUpdate).then((result) => {
    if (result && result.status == 200) {
        swal({
            title: "Success",
            text: "Password Updated Successfully",
            icon: "success",
            button: "Ok",
        }).then(() => {
            window.location.reload();
        });
    } else {
        swal({
            icon: "error",
            title: "Update Password",
            text: "Incorrect Details",
            button: "Continue",
            // currentPassword: "",
            // newPassword: "",
            // confirmpassword: "",
        }).then(() => {
            window.location.reload();  // instead of reloading tab, I want to clear input fields so I can give input again till satified condtions
            // window.location.href = "/company/profile/";
            //  if (values.currentPassword !== user.password) {
            //  errors.currentPassword = "Wrong Password";
            //  values.currentPassword = "";
            // setFieldValue("currentPassword", "");
            // setFieldValue("newPassword", "");
            // setFieldValue("confirmpassword", "");
            // }
        });

    }
});

I also tried to validate :

else if (values.currentPassword !== user.password) {
    errors.currentPassword = "Wrong Password";
    values.currentPassword = "";
}

But it always gives 'Wrong Password' text even for correct one and not getting cleared input fields.

enter image description here

I tried to console it. Why it is printing on console for every digit that we entered ? Also, user password is encrypted, then ways to compare them ? See image: enter image description here

Can you help me, how to clear/reset input fields of updating password popup if current password is not matching from user's current password.

  • how do you expect them to be equal? – Ahmed Sbai Jul 05 '23 at 05:40
  • @Hatana, yes, we can not compare like that, either we need encrypt values.currentPassword. But I read somewhere that two identical password can have different hash value. I tried it. Then can we decrypt user.password before comparing ? – Display Name is missing Jul 05 '23 at 08:05

0 Answers0