图案验证

图案验证是一个 Swift 包,为 iOS 应用程序提供了一个可定制的基于 3x3 网格的图案验证系统。它提供了一种安全且具有视觉吸引力的方式来实现用户身份验证或图案创建。这在多用户设备上的应用程序中非常有用,可以消除每个用户都需要通过电子邮件/密码验证登录的需求。

PatternAuthenticationDemo.webm

特性

要求

安装

Swift Package Manager

将以下行添加到您的 Package.swift 文件的依赖项中

.package(url: "https://github.com/yourusername/PatternAuthentication.git", from: "1.0.0")

然后,将 "PatternAuthentication" 作为目标的依赖项包含进去

.target(name: "YourTarget", dependencies: ["PatternAuthentication"]),

用法

导入包

import PatternAuthentication

创建图案设置视图

GridAuthenticator(.set(
    minimumVertices: 6,
    color: .green,
    interactionMode: .drag,
    requireConfirmation: true,
    repeatInput: true,
    debug: false
) { hash in
    print("New pattern hash: \(hash)")
    // Store this hash securely for later authentication
    // if `requireConfirmation` is set to true it will automatically have the user confirm the pattern prior to calling completion
})

创建验证视图

let expectedHash = user.patternHash // retrieve expected hash from storage

GridAuthenticator(.authenticate(
    expectedHash: expectedHash,
    color: .blue,
    interactionMode: .drag,
    debug: false
) { success in
    if success {
        print("Authentication successful")
         // here's where we would navigate to a new authenticated area, show a success animation, etc
    } else {
        print("Authentication failed")
         // here's where we would show a failure message, increase attempt counts, etc
    }
})

自定义

可以使用以下参数自定义 GridAuthenticator 视图

安全性

图案验证使用 SHA-256 哈希安全地存储和比较图案。 实际的图案永远不会被存储,只存储它的哈希值。

故障排除

如果您遇到任何问题

  1. 确保您使用的是最新版本的包。
  2. 检查您的 iOS 部署目标是否设置为 iOS 15.0 或更高版本。
  3. 如果使用调试模式,请验证当前哈希是否与预期哈希匹配。

贡献

欢迎对图案验证包做出贡献。请随时提交合并请求。

支持

如有问题、错误报告或功能请求,请在 GitHub 存储库上打开一个 issue。

路线图和已知问题

许可证

图案验证是在 MIT 许可下提供的。 有关更多信息,请参见 LICENSE 文件。