微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何验证令牌解密

如何解决如何验证令牌解密

我想用ionic进行指纹认证:

意思是当用户扫描他的手指时,用户的身份将自动添加到表单中:就像在这个视频中https://youtu.be/E6fZcJTNoCA

我想成功,但我不知道该怎么做

我得到了令牌(密码加密),但我不知道如何使用这个令牌来获取(解密密码)

请帮我解决这个问题

这是HTML代码

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Akaya+Telivigala&display=swap" rel="stylesheet">

<ion-header [translucent]="true" class="ion-no-border">
  <ion-toolbar>
    <div class="black-circle"></div>
    <ion-title class="ion-text-center custom-font">Se Connecter</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
  <svg class="back-bolb" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
    <path fill="#CCCCCC" d="M65,-20C70,-5.6,50.1,18,26.8,34.3C3.5,50.7,-23.3,59.7,-41.2,48.6C-59.1,37.5,-68.2,6.2,-59.9,-12.8C-51.5,-31.7,-25.8,-38.3,2.1,-39C30,-39.7,59.9,-34.4,65,-20Z" transform="translate(100 100)" />
  </svg>

  <div class="ion-padding">

    <form class="ion-no-padding" [formGroup]="Form" (ngSubmit)="logForm()">
       <div class="wrap-input">
         <input class="input" type="number" formControlName="employeeN" required placeholder="Numero de matricule">
       </div>
      <span class="error" *ngIf="employeeN.invalid && employeeN.touched"><small > <ion-icon name="close-circle-outline"></ion-icon> Matricule est nécessaire </small></span>
       <div class="wrap-input">
        <input class="input" type="password" formControlName="password" required placeholder="Le Mot de passe">
       </div>
       <span class="error" *ngIf="password.invalid && password.touched"><small > <ion-icon name="close-circle-outline"></ion-icon> Saisire votre mode de passe de longeur min 8 </small></span>
       <div class ="container-form-btn">
            <button [disabled]="!Form.valid" class="form-btn custom-font">
              Soumettre
            </button>
       </div>
    </form>
      <!-- here i add the button to add the fingerprint-->
    <ion-fab vertical="end" horizontal="end" slot="fixed" class="finger">
      <ion-fab-button id="fingerbtn" (click)="fingerScan()">
        <ion-icon name="finger-print" id="fingerIcon"></ion-icon>
      </ion-fab-button>
    </ion-fab>
    <button (click)='decript()'>decrypt</button>
  </div>
</ion-content>

这是 ts 文件

import { Component } from '@angular/core';
import {Validators,FormBuilder,FormGroup } from '@angular/forms';
import { AndroidFingerprintAuth } from '@ionic-native/android-fingerprint-auth/ngx';
import { Router } from '@angular/router';

@Component({
  selector: 'app-home',templateUrl: 'home.page.html',styleUrls: ['home.page.scss'],})
export class HomePage  {
  user={
    clientId:'1',username:'youssef',matricule:12123,password:'youssef115'
  }
  token='';
  Form : FormGroup;
  constructor(private formBuilder: FormBuilder,private router: Router,private androidFingerprintAuth: AndroidFingerprintAuth) {
    this.Form = this.formBuilder.group({
      employeeN: ['',[Validators.required,Validators.min(10000),Validators.max(99999)]],password: ['',Validators.minLength(8)]],});
  }

  logForm(){
    console.log(this.Form.value);
    this.router.navigate(['authonticated']);
  }

 get employeeN(){
   return this.Form.get('employeeN');
 }
 get password(){
   return this.Form.get('password');
 }

 fingerScan(){
  // this.Form.setValue({employeeN:12344,password:'youssef11528'});
  this.androidFingerprintAuth.isAvailable()
  .then((result)=> {
    if(result.isAvailable){
      // it is available

      this.androidFingerprintAuth.encrypt({ clientId: this.user.clientId,username: this.user.username,password: this.user.password })
        .then(result => {
           if (result.withFingerprint) {
               console.log('Successfully encrypted credentials.');
               alert('Encrypted credentials: ' + result.token);
               this.token=result.token;
           } else if (result.withBackup) {
             console.log('Successfully authenticated with backup password!');
           } else console.log('Didn\'t authenticate!');
        })
        .catch(error => {
           if (error === this.androidFingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
             console.log('Fingerprint authentication cancelled');
           } else console.error(error)
        });

    } else {
      // fingerprint auth isn't available
    }
  })
  .catch(error => console.error(error));

 }

 decript(){
   alert(this.token)
  this.androidFingerprintAuth.isAvailable()
  .then((result)=> {
  if(result.isAvailable){

      this.androidFingerprintAuth.decrypt({ clientId: this.user.clientId,password: this.token })
        .then(result => {
           if (result.withFingerprint) {
               console.log('Successfully encrypted credentials.');
              if (result.password){
                alert("password: " + result.password);

              }
           } else if (result.withBackup) {
             console.log('Successfully authenticated with backup password!');
           } else console.log('Didn\'t authenticate!');
        })

        .catch(error => {
           if (error === this.androidFingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
             console.log('Fingerprint authentication cancelled');
           } else console.error(error)
        });

    } else {
      // fingerprint auth isn't available
    }
  })
  .catch(error => alert(error));
 }
 }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。