图案验证是一个 Swift 包,为 iOS 应用程序提供了一个可定制的基于 3x3 网格的图案验证系统。它提供了一种安全且具有视觉吸引力的方式来实现用户身份验证或图案创建。这在多用户设备上的应用程序中非常有用,可以消除每个用户都需要通过电子邮件/密码验证登录的需求。
将以下行添加到您的 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
视图
color
: 网格和效果的主要颜色 [默认值:blue
]interactionMode
: 选择 .tap
或 .drag
作为图案输入 [默认值:.drag
]debug
: 启用或禁用调试信息显示。这将添加一些额外的日志记录和一些调试 UI 元素 [默认值:false
]minimumVertices
: 设置有效图案所需的最小点数(仅设置模式)[默认值:6
]requireConfirmation
: 用户将被要求在调用完成之前确认他们的图案(仅设置模式)[默认值:true
]repeatInput
: 在用户初始输入之后和确认输入之前,将为用户重复显示图案(仅设置模式)[默认值:true
]图案验证使用 SHA-256 哈希安全地存储和比较图案。 实际的图案永远不会被存储,只存储它的哈希值。
如果您遇到任何问题
欢迎对图案验证包做出贡献。请随时提交合并请求。
如有问题、错误报告或功能请求,请在 GitHub 存储库上打开一个 issue。
.tap
交互当前未激活。传递 .tap
不会改变输入图案验证是在 MIT 许可下提供的。 有关更多信息,请参见 LICENSE 文件。