Swiftpack.co - scr037/zxcvbn-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by scr037.
scr037/zxcvbn-swift 1.2.0
This is a contribution to the low budget password strength checker (https://github.com/dropbox/zxcvbn) compatible with swift package manager.
⭐️ 3
🕓 2 years ago
iOS
.package(url: "https://github.com/scr037/zxcvbn-swift.git", from: "1.2.0")

zxcvbn-swift

This is a swift compatible implementation of the password strength checker zxcvbn and a relies on the one specific contribution aimed for iOS. Check it out here. zxcvbn-swift is easier to integrate since it's compabile with Swift Package Manager.

Installation

Using swift package manager. Follow instructions here.

https://github.com/scr037/zxcvbn-swift

Usage

One to use zxcvbn-swift is to use DBPasswordStrengthMeter. This is a built-in component from the original implementation:

import ZxcvbnSwift

lazy var meterView = DBPasswordStrengthMeterView()

lazy var passwordField: UITextField = {
    let field = UITextField()
    field.isSecureTextEntry = true
    field.autocorrectionType = .no
    field.autocapitalizationType = .none
    field.placeholder = "Type a password here"
    field.addTarget(self, action: #selector(textFieldEditingDidChange(_:)), for: .editingChanged)
    field.rightViewMode = .always
    field.rightView = self.meterView
    field.borderStyle = .roundedRect
    return field
}()

// You can add a target to your editing text field or implement
// your preferred method from UITextFieldDelegate.
@objc func textFieldEditingDidChange(_ textField: UITextField) {
    guard let password = textField.text else { return }
    self.meterView.scorePassword(password)
}

If you prefer creating a custom UI component for diplaying your password strength, you can use DBZxcvbn straight away:

import ZxcvbnSwift

lazy var let checker = DBZxcvbn()

{ ... }

// You can add a target to your editing text field or implement
// your preferred method from UITextFieldDelegate.
@objc func textFieldEditingDidChange(_ textField: UITextField) {
    guard let password = textField.text else { return }
    self.meterView.scorePassword(password)
    let strength = checker.passwordStrength(password)
    // Score is an Int32 representation between 0 and 4. 
    // You can easily display this result within a UIProgressView 
    // by multiplying for a 0.25 factor.
    notifyPasswordStrength(strength?.score)
}

GitHub

link
Stars: 3
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Set minimum deployment target to iOS 13
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics