The PassGuard
provides visual feedback to help users create stronger passwords by identifying common mistakes. The PassGuard uses 16 algorithms of different complexities. Each algorithm assigns a score to the input password using a specific formula. These scores are then combined to calculate a final score, which can range from 0 to 100.
The PassGuard runs on the user device as a framework and does not store or send user password over the network.
PassGuard
works on iOS 13.0+. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
- Foundation.framework
- UIKit.framework
- SwiftUI.framework
- Combine.framework
optional
CocoaPods is the recommended way to add PassGuard to your project.
- Add a pod entry for PassGuard to your Podfile `pod 'PassGuard'
- Install the pod(s) by running
pod install
. - Include PassGuard wherever you need it with
#import PassGuard
.
platform :ios, '13.0'
use_frameworks!
target 'MyApp' do
pod 'PassGuard'
end
You can use The Swift Package Manager to install PassGuard by adding the proper description to your Package.swift file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/mehrankmlf/PassGuard.git", from: "1.0.8"),
]
)
Then run swift build whenever you get prepared.
You can create your custom UI based on the project.
(see sample Xcode project in /Example)
import PassGuard
We have a Combine text publisher that allows us to stream user input from the UITextField, and there are additional solutions to capture user input efficiently when using UIKit. PassGuard offers this straightforward approach.
txtPassword.passGuardTextPublisher
.sink { [weak self] password in
// password
}
.store(in: &cancellables)
To use PassGuard, you should create an instance from the framework to measure the user's entered password strength.
let passGuard = PassGuard(password: password)
In this version, PassGuard provides three options for building the UI responsible for displaying password details to the end user.
- Strength Description: "Too Short", "Very Weak", "Weak", "Medium", "Strong", "Very Strong". The six-level return is determined by the password score and strength calculated by PassGuard. You can customize these six strings as I will explain below.
- Strength Color: The framework returns six colors in a spectrum ranging from red to green.
- Strenght Score: The framework returns a score calculated using the 16 algorithms provided by PassGuard.
- Strenght Type: The framework returns an enum to identify the actual level of password strength. The enum cases are tooShort, veryWeak, weak, medium, strong, veryStrong which you can use to get the current state of PassGuard.
let passGuard = PassGuard(password: password)
self?.lblStrenght.text = passGuard.strengthDescription
self?.lblStrenght.backgroundColor = passGuard.strengthColor
self?.strenghtProgressView.progress = Float(passGuard.strengthScore) / 100
I have explained about PassGuard in the form of a post on Medium.
PassGuard allows you to customize the description returned by the framework based on the password score. You simply need to create a string array with six indexes and assign it to the PassGuard instance.
let customDescriptions = ["Way Too Short",
"Extremely Weak",
"Not So Strong",
"Fairly Strong",
"Super Strong", "Incredibly Strong"]
txtPassword.passGuardTextPublisher
.sink { [weak self] password in
let passGuard = PassGuard(password: password,
customDescription: customDescriptions)
self?.lblStrenght.text = passGuard.strengthDescription
self?.lblStrenght.backgroundColor = passGuard.strengthColor
self?.strenghtProgressView.progress = Float(passGuard.strengthScore) / 100
}
.store(in: &cancellables)
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/YourFeatureName
) - Commit your Changes (
git commit -m 'Add some YourFeatureName'
) - Push to the Branch (
git push origin feature/YourFeatureName
) - Open a Pull Request
MIT License
Copyright (c) 2023 Related Code
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.