4

我们可以在手机上注册生物指纹吗?我在谷歌上搜索并找到了 loca_auth颤振插件,但它只能获取生物特征指纹列表并验证指纹,但我需要在设备中注册生物特征指纹。

4

3 回答 3

3

第三方应用程序不具备向设备注册/添加生物特征材料的能力,无论您使用什么平台——颤振等。以下是流程的一般工作方式。

  1. 用户获得一部新手机(购买的、赠送的、找到的等),一部支持生物特征认证的手机。
  2. 用户进入设置并注册一个生物特征模板(例如注册他们的指纹作为解锁设备的一种方式)。一般来说,这是注册/登记指纹/面部/虹膜/等的唯一方法。
  3. 您的应用程序希望用户使用生物识别技术进行身份验证,因此实现了类似于此处此处描述的内容。

现在在您的应用程序中,当用户点击 时authenticate(),您的应用程序实际上不会看到任何生物特征材料。生物识别材料保存在安全的位置,以便第三方应用程序无法访问它们。您的应用程序从框架中得到确认,即尝试在您的应用程序中进行身份验证的指纹/面部/虹膜确实已在设备上注册。查看我提到的博客文章以获取更多详细信息。

于 2019-12-23T17:41:44.053 回答
1

你可以这样做。看看这个: Flutter 中的指纹认证

因此,您还需要在 android manifest 文件中设置权限。

于 2019-11-11T15:44:22.950 回答
0

这是在我们的应用程序中实现指纹认证的代码,并带有一个完整的示例

首先FingerprintAuthentication上课

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/auth_strings.dart';
import 'package:local_auth/local_auth.dart';
import 'package:lottie/lottie.dart';
import 'package:nb_utils/nb_utils.dart';
import 'package:prokit_flutter/main.dart';
import 'package:prokit_flutter/main/utils/AppColors.dart';
import 'package:prokit_flutter/main/utils/AppWidget.dart';

class FingerprintAuthentication extends StatefulWidget {
  static String tag = '/FingerprintAuthentication';

  @override
  _FingerprintAuthenticationState createState() => _FingerprintAuthenticationState();
}

class _FingerprintAuthenticationState extends State<FingerprintAuthentication> {
  final LocalAuthentication auth = LocalAuthentication();
  bool face = false;
  bool fingerprint = false;
  String _authorized = 'Not Authorized';
  bool _isAuthenticating = false;
  bool authorized = false;

  @override
  void initState() {
    super.initState();
    init();
  }

  init() async {
    await _getAvailableBiometrics();
  }

  @override
  void setState(fn) {
    if (mounted) super.setState(fn);
  }

  Future<void> _getAvailableBiometrics() async {
    List<BiometricType> availableBiometrics = await auth.getAvailableBiometrics();
    try {
      face = availableBiometrics.contains(BiometricType.face);
      fingerprint = availableBiometrics.contains(BiometricType.fingerprint);

      setState(() {});
    } on PlatformException catch (e) {
      print(e);
    }
  }

  Future<void> _authenticate() async {
    bool authenticated = false;
    try {
      setState(() {
        _isAuthenticating = true;
        _authorized = 'Authenticating';
      });

      authenticated = await auth.authenticateWithBiometrics(
        localizedReason: 'Scan your fingerprint to Login',
        useErrorDialogs: true,
        stickyAuth: true,
        iOSAuthStrings: IOSAuthMessages(
          cancelButton: 'cancel',
          goToSettingsButton: 'settings',
          goToSettingsDescription: 'Please set up your Touch ID.',
          lockOut: 'Please reenable your Touch ID',
        ),
        androidAuthStrings: AndroidAuthMessages(
            signInTitle: "Fingerprint Authentication",
            fingerprintRequiredTitle: "Connect to Login",
            cancelButton: 'Cancel',
            goToSettingsButton: 'Setting',
            goToSettingsDescription: 'Please set up your Touch ID.',
            fingerprintSuccess: "Authentication Successfully authenticated"),
      );

      authorized = authenticated;
      setState(() {
        _isAuthenticating = false;
        _authorized = 'Authenticating';
      });
    } on PlatformException catch (e) {
      showDialog(
          context: context,
          builder: (BuildContext context) {
            return HandleError(
              code: e.code,
              message: e.message,
            );
          });
    }
    if (!mounted) return;

    final String message = authenticated ? 'Authorized' : 'Not Authorized';
    setState(() {
      authorized = authenticated;
      _authorized = message;
    });
    await Future.delayed(Duration(seconds: 3));
    setState(() {
      authorized = authenticated;
    });
  }

  void _cancelAuthentication() {
    auth.stopAuthentication();
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        appBar: appBar(context, 'Fingerprint Authentication'),
        body: ListView(
          shrinkWrap: true,
          physics: BouncingScrollPhysics(),
          padding: EdgeInsets.all(16),
          scrollDirection: Axis.vertical,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                fingerprint
                    ? InkWell(
                        borderRadius: BorderRadius.circular(10),
                        onTap: _isAuthenticating ? _cancelAuthentication : _authenticate,
                        child: Container(
                          padding: EdgeInsets.all(16),
                          decoration: BoxDecoration(
                            border: Border.all(color: appColorPrimary),
                            borderRadius: BorderRadius.circular(10),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Icon(
                                Icons.fingerprint,
                                color: appColorPrimary,
                                size: 75,
                              ),
                              10.height,
                              Text(
                                'Fingerprint',
                                style: boldTextStyle(
                                  color: appColorPrimary,
                                ),
                              )
                            ],
                          ),
                        ),
                      )
                    : InkWell(
                        borderRadius: BorderRadius.circular(10),
                        onTap: () {
                          toast("Fingerprint not available");
                        },
                        child: Container(
                          padding: EdgeInsets.all(16),
                          decoration: BoxDecoration(
                            border: Border.all(color: Colors.grey),
                            borderRadius: BorderRadius.circular(10),
                          ),
                          child: Column(
                            children: [
                              Icon(
                                Icons.fingerprint,
                                color: Colors.grey,
                                size: 75,
                              ),
                              10.height,
                              Text(
                                'Fingerprint',
                                style: boldTextStyle(
                                  color: Colors.grey,
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
                face
                    ? InkWell(
                        borderRadius: BorderRadius.circular(10),
                        onTap: _isAuthenticating ? _cancelAuthentication : _authenticate,
                        child: Container(
                          padding: EdgeInsets.all(16),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10),
                            border: Border.all(
                              color: appColorPrimary,
                            ),
                          ),
                          child: Column(
                            children: [
                              Icon(Icons.face, color: appColorPrimary, size: 75),
                              10.height,
                              Text(
                                'Face',
                                style: boldTextStyle(
                                  color: appColorPrimary,
                                ),
                              )
                            ],
                          ),
                        ),
                      )
                    : InkWell(
                        borderRadius: BorderRadius.circular(10),
                        onTap: () {
                          toast("Face biometric is unavailable");
                        },
                        child: Container(
                          padding: EdgeInsets.all(16),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10),
                            border: Border.all(
                              color: Colors.grey,
                            ),
                          ),
                          child: Column(
                            children: [
                              Icon(Icons.face, color: Colors.grey, size: 75),
                              10.height,
                              Text(
                                'Face',
                                style: boldTextStyle(
                                  color: Colors.grey,
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
              ],
            ),
            authorized
                ? Lottie.asset(
                    'images/integrations/img/authentication.json',
                    height: 250,
                    width: 250,
                    reverse: true,
                    animate: mounted,
                    repeat: false,
                  )
                : SizedBox(),
          ],
        ),
      ),
    );
  }
}

并创建一个HandleError

  class HandleError extends StatelessWidget {
      final String code;
      final String message;
    
      HandleError({this.code, this.message});
    
      @override
      Widget build(BuildContext context) {
        return Dialog(
          child: Container(
            decoration: BoxDecoration(
              color: appStore.scaffoldBackground,
              shape: BoxShape.rectangle,
              borderRadius: BorderRadius.circular(0),
            ),
            width: MediaQuery.of(context).size.width,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Container(
                  padding: EdgeInsets.all(8),
                  color: appColorPrimary,
                  child: Column(
                    children: [
                      Icon(
                        Icons.error_outline,
                        color: Colors.white,
                        size: 75,
                      ),
                      Text(code.validate(), textAlign: TextAlign.center, style: boldTextStyle(size: 18, color: white)),
                    ],
                  ),
                ),
                Text(
                  message.validate(),
                  style: secondaryTextStyle(),
                  textAlign: TextAlign.justify,
                ).paddingOnly(left: 8, right: 8),
                16.height,
                FlatButton(
                  onPressed: () {
                    finish(context);
                  },
                  child: MaterialButton(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10),
                    ),
                    color: Colors.red,
                    onPressed: () {
                      finish(context);
                    },
                    child: (Text(
                      'Retry',
                      style: boldTextStyle(color: Colors.white),
                    )),
                  ),
                ),
                16.height,
              ],
            ),
          ),
        );
      }
    }
于 2021-04-24T02:23:30.650 回答