Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

toddheasley/zxcvbn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

_________________________________________________/\/\___________________
_/\/\/\/\/\__/\/\__/\/\____/\/\/\/\__/\/\__/\/\__/\/\________/\/\/\/\___
_____/\/\______/\/\/\____/\/\________/\/\__/\/\__/\/\/\/\____/\/\__/\/\_
___/\/\________/\/\/\____/\/\__________/\/\/\____/\/\__/\/\__/\/\__/\/\_
_/\/\/\/\/\__/\/\__/\/\____/\/\/\/\______/\______/\/\/\/\____/\/\__/\/\_
________________________________________________________________________

Zxcvbn attempts to give sound password advice through pattern matching and conservative entropy calculations. It finds common passwords, common American names and surnames, common English words and common patterns like dates, repeated characters, sequences, and QWERTY patterns.

Read Dan Wheeler's zxcvbn: realistic password strength estimation for the original author's explanation.

This implementation for Swift Package Manager expands support to all Apple platforms, while carefully matching the evaluation behavior, results and functionality of its Objective-C ancestor.

Requirements

Targets iOS/iPadOS/tvOS 14, watchOS 7 and macOS 11 Big Sur. Written in Swift 5.6 and requires Xcode 13.3 or newer to build. Command-line interface depends on Swift Argument Parser.

Command-Line Interface

Included in the package

Example Usage

Password evaluation is exposed as a function of String:

import Foundation
import Zxcvbn

let result: Result = "coRrecth0rseba++ery9.23.2007staple$".zxcvbn()
print(result.score) // strong

Optionally, penalize context-specific strings, like a user's name or email address, by extending the built-in dictionaries with a custom list:

import Foundation
import Zxcvbn

let result: Result = "coRrecth0rseba++ery9.23.2007staple$".zxcvbn(custom: [
    "example@aol.com",
    "example",
    "aol"
])

SwiftUI Support

Zxcvbn includes ResultView, a SwiftUI replacement for DBPasswordStrengthMeterView when moving from the Objective-C implementation.

import SwiftUI
import Zxcvbn

struct ContentView: View {
    @State private var text: String = ""
    
    var body: some View {
        SecureField("Password", text: $text)
            .textFieldStyle(RoundedBorderTextFieldStyle())
            .overlay(ResultView(text), alignment: .trailing)
    }
}

Acknowledgments

Ported from the Dropbox Objective-C implementation by Leah Culver.