Giter Site home page Giter Site logo

navajo-swift's Introduction

Navajo-Swift

Password Validator & Strength Evaluator

Navajo is named in honor of the famed code talkers of the Second World War.

Original Project

Navajo by Mattt Thompson

This project is not compatible with the original project.

Installation

Platform Swift 4.0 Travis-CI Carthage compatible Version

Carthage

github "jasonnam/Navajo-Swift"

CocoaPods

use_frameworks!
pod 'Navajo-Swift'
import Navajo_Swift

Manual

Just copy the files in Source folder into your project.

Usage

Evaluating Password Strength

Password strength is evaluated in terms of information entropy.

let password = passwordField.text ?? ""
let strength = Navajo.strength(ofPassword: password)

strengthLabel.text = Navajo.localizedString(forStrength: strength)

Validating Password

let lengthRule = LengthRule(min: 6, max: 24)
let uppercaseRule = RequiredCharacterRule(preset: .LowercaseCharacter)

validator = PasswordValidator(rules: [lengthRule, uppercaseRule])

if let failingRules = validator.validate(password) {
    validationLabel.textColor = .red
    validationLabel.text = failingRules.map({ return $0.localizedErrorDescription }).joined(separator: "\n")
} else {
    validationLabel.textColor = .green
    validationLabel.text = "Valid"
}

Available Validation Rules

  • Allowed Characters
  • Required Characters (custom, lowercase, uppercase, decimal, symbol)
  • Non-Dictionary Word
  • Minimum / Maximum Length
  • Predicate Match
  • Regular Expression Match
  • Block Evaluation

If you are using the Predicate and Regex rules, remember that when password is matching to them it is considered to be invalid. For example, we can check if users are using for example "password123" as their password by following rule object.

let rule = PredicateRule(predicate: NSPredicate(format: "SELF BEGINSWITH %@", "PASSWORD"))

For the block rule, it is considered to be invalid when the block returns true.

Localization

Keys for the localizable strings Localization Tutorial or check the demo app in the repository.

Password Strength

  • NAVAJO_VERY_WEAK
  • NAVAJO_WEAK
  • NAVAJO_REASONABLE
  • NAVAJO_STRONG
  • NAVAJO_VERY_STRONG

Password Validation

  • NAVAJO_ALLOWED_CHARACTER_ERROR
  • NAVAJO_REQUIRED_CHARACTER_REQUIRED_ERROR
  • NAVAJO_REQUIRED_CHARACTER_LOWERCASE_ERROR
  • NAVAJO_REQUIRED_CHARACTER_UPPERCASE_ERROR
  • NAVAJO_REQUIRED_CHARACTER_DECIMAL_DIGIT_ERROR
  • NAVAJO_REQUIRED_CHARACTER_SYMBOL_ERROR
  • NAVAJO_DICTIONARYWORD_ERROR
  • NAVAJO_LENGTH_ERROR
  • NAVAJO_PREDICATE_ERROR
  • NAVAJO_REGEX_ERROR
  • NAVAJO_BLOCK_ERROR

Contact

Any feedback and pull requests are welcome :)

Jason Nam
Website
Email

License

Navajo-Swift is available under the MIT license. See the LICENSE file for more info.

navajo-swift's People

Contributors

jasonnam avatar supertango avatar

Watchers

 avatar James Cloos avatar Steve Petersen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.