PasswordRules
A Swift library for defining strong password generation rules
Install / Use
/learn @NSHipster/PasswordRulesREADME
PasswordRules
A Swift library for defining strong password generator rules.
This functionality is discussed in the NSHipster article Password Rules / UITextInputPasswordRules.
Requirements
- Swift 4.0+
Installation
Swift Package Manager
Add the PasswordRules package to your target dependencies in Package.swift:
import PackageDescription
let package = Package(
name: "YourProject",
dependencies: [
.package(
url: "https://github.com/NSHipster/PasswordRules",
from: "1.0.0"
),
]
)
Then run the swift build command to build your project.
Carthage
To use PasswordRules in your Xcode project using Carthage,
specify it in Cartfile:
github "NSHipster/PasswordRules" ~> 1.0.0
Then run the carthage update command to build the framework,
and drag the built PasswordRules.framework into your Xcode project.
Usage
Define an array of PasswordRules cases
and use the descriptor(for:) method to create a string representation:
import PasswordRules
let rules: [PasswordRule] = [ .required(.upper),
.required(.lower),
.required(.special),
.minLength(20) ]
let descriptor = PasswordRule.descriptor(for: rules)
// "required: upper; required: lower; required: special; minlength: 20;"
Initialize a UITextInputPasswordRules object using the descriptor
and pass that to the passwordRules property of a secure text field:
import UIKit
guard #available(iOS 12, *) else {
fatalError()
}
self.passwordTextField.passwordRules =
UITextInputPasswordRules(descriptor: descriptor)
License
MIT
Contact
NSHipster (@NSHipster)
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
