ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 275.5k

How validate old password with current password exist on db

Jan 10 2020 9:12 AM
problem
How validate old password with current password exist on db ?
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
  1. <div class="form-group">  
  2.   <label >OldPassword</label><br>  
  3.   <input type="password" formControlName="oldPassword" class="textboxclass"   [ngClass]="{ 'is-invalid': submitted && c.oldPassword.errors }" />  
  4.   <div *ngIf="submitted && c.oldPassword.errors" class="invalid-feedback">  
  5.       <div *ngIf="c.oldPassword.errors.required">Password is required</div>  
  6.       <div *ngIf="c.oldPassword.errors.minlength">Password must be at least 6 characters</div>  
  7.   </div>  
  8. </div>  
  9.   
  10. on ts  
  11. oldPassword = new FormControl('', [Validators.required, Validators.minLength(6), Validators.maxLength(10)]);  
  12.   ngOnInit() {  
  13.     this.createFormResetPassword();  
  14.   }  
  15. createFormResetPassword() {  
  16.     this.ChangePasswordForm = this.formBuilder.group({  
  17.       
  18.       oldPassword: this.oldPassword,  
  19.   
  20.     }  
  21.   }  
  22. onSubmit() {  
  23.     this.submitted = true;  
  24.   
  25.   
  26.     if (this.ChangePasswordForm.invalid) {  
  27.       console.log("status failed ");  
  28.         return;  
  29.     }  
  30.     this.loading = true;  
  31.     this.userservice.changePassword()  
  32.         .pipe(first())  
  33.         .subscribe(  
  34.             data => {  
  35.              });  
  36.                console.log("data values" + data);  
  37.                this.toastr.success('Users  Added Successfully');  
  38.             },  
  39.             error => {  
  40.                 this.error = error;  
  41.                 this.loading = false;  
  42.             });  
  43.   }  
 

Answers (4)