Click here to Skip to main content
14,423,094 members
Rate this:
Please Sign up or sign in to vote.
problem
How validate old password with current password exist on db on angular 7 ?
I have user on database his name
michel
and password 1234567
I need when write old password on angular 7
check password exist on database for user michel as 1234567
with
password he write
if two is same not problem
but if he write password different for this
display error message

What I have tried:

<div class="form-group">  
  <label >OldPassword</label><br>  
  <input type="password" formControlName="oldPassword" class="textboxclass"   [ngClass]="{ 'is-invalid': submitted && c.oldPassword.errors }" />  
  <div *ngIf="submitted && c.oldPassword.errors" class="invalid-feedback">  
      <div *ngIf="c.oldPassword.errors.required">Password is required</div>  
      <div *ngIf="c.oldPassword.errors.minlength">Password must be at least 6 characters</div>  
  </div>  
</div>  
  
on ts  
oldPassword = new FormControl('', [Validators.required, Validators.minLength(6), Validators.maxLength(10)]);  
  ngOnInit() {  
    this.createFormResetPassword();  
  }  
createFormResetPassword() {  
    this.ChangePasswordForm = this.formBuilder.group({  
      
      oldPassword: this.oldPassword,  
  
    }  
  }  
onSubmit() {  
    this.submitted = true;  
  
  
    if (this.ChangePasswordForm.invalid) {  
      console.log("status failed ");  
        return;  
    }  
    this.loading = true;  
    this.userservice.changePassword()  
        .pipe(first())  
        .subscribe(  
            data => {  
             });  
               console.log("data values" + data);  
               this.toastr.success('Users  Added Successfully');  
            },  
            error => {  
                this.error = error;  
                this.loading = false;  
            });  
  }  
Posted
Comments
Richard Deeming 10-Jan-20 11:07am
   
Well, for a start, you're hopefully not storing the password in the database in plain text.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

To validate the old password, you load the salt and salted password hash from the database; compute a new salted hash using the loaded salt and the entered password; and then compare the computed hash with the loaded hash.
Maciej Los 10-Jan-20 15:13pm
   
My virtual 5!
MadMyche 10-Jan-20 13:56pm
   
Without knowing what kind of password system you are using; how are we supposed to be able to help with this?
The code you provided has absolutely nothing to do with the actual task at hand.
Maciej Los 10-Jan-20 15:13pm
   
Agree!
ZurdoDev 10-Jan-20 16:16pm
   
Validating the password has nothing to do with angular. What did you want us to do?
ahmed_sa 10-Jan-20 16:39pm
   
i want to validate old password with new password but problem i have validation on form to new password and confirm password
so please my question how to make two custom validation on reactive form
more than one
createFormResetPassword() {
this.ChangePasswordForm = this.formBuilder.group({

userName:this.userName,
oldPassword: this.oldPassword,
newPass: this.newPass,
confirmedPassword: this.confirmedPassword
},
{ validator: MustMatch('newPass', 'confirmedPassword')}
// error here not accept { validator: MustnotMatch('oldPassword', 'newPass')}

);

}
so how to add more custom validation to reactive form
MadMyche 11-Jan-20 8:57am
   
AGAIN, we need to KNOW HOW the password is being saved to figure out how to check it; AND, how to display it (via validation) comes later on AND is dependent upon checking it first.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100