Pattern Authentication is a Swift package that provides a customizable 3x3 grid-based pattern authentication system for iOS applications. It offers a secure and visually appealing way to implement user authentication or pattern creation. This is useful in applications that may be on multi-user devices to eliminate needing to have every user login via email/password auth.
PatternAuthenticationDemo.webm
- Grid-based pattern authentication
- Customizable appearance (colors, interaction modes)
- Support for both authentication and pattern creation
- Particle effects for enhanced visual feedback
- Shake animation for incorrect attempts
- Debug mode for development and testing
- Minimum pattern length enforcement
- Cryptographic hashing for secure pattern storage
- iOS 15.0+
- Swift 5.10+
Add the following line to your Package.swift
file's dependencies:
.package(url: "https://github.com/yourusername/PatternAuthentication.git", from: "1.0.0")
Then, include "PatternAuthentication" as a dependency for your target:
.target(name: "YourTarget", dependencies: ["PatternAuthentication"]),
import PatternAuthentication
GridAuthenticator(.set(
minimumVertices: 6,
color: .green,
interactionMode: .drag,
requireConfirmation: true,
repeatInput: true,
debug: false
) { hash in
print("New pattern hash: \(hash)")
// Store this hash securely for later authentication
// if `requireConfirmation` is set to true it will automatically have the user confirm the pattern prior to calling completion
})
let expectedHash = user.patternHash // retrieve expected hash from storage
GridAuthenticator(.authenticate(
expectedHash: expectedHash,
color: .blue,
interactionMode: .drag,
debug: false
) { success in
if success {
print("Authentication successful")
// here's where we would navigate to a new authenticated area, show a success animation, etc
} else {
print("Authentication failed")
// here's where we would show a failure message, increase attempt counts, etc
}
})
The GridAuthenticator
view can be customized using the following parameters:
color
: The primary color of the grid and effects [default:blue
]interactionMode
: Choose between.tap
or.drag
for pattern input [default:.drag
]debug
: Enable or disable debug information display. This adds some additional logging and some debug UI elements [default:false
]minimumVertices
: Set the minimum number of points required for a valid pattern (setup mode only) [default:6
]requireConfirmation
: User will be asked to confirm their pattern prior to completion being called (setup mode only) [default:true
]repeatInput
: The pattern will be repeated back for the user after their initial input and before their confirmation input (setup mode only) [default:true
]
Pattern Authentication uses SHA-256 hashing to securely store and compare patterns. The actual pattern is never stored, only its hash.
If you encounter any issues:
- Ensure you're using the latest version of the package.
- Check that your iOS deployment target is set to iOS 15.0 or later.
- If using the debug mode, verify that the current hash matches the expected hash.
Contributions to the Pattern Authentication package are welcome. Please feel free to submit a Merge Request.
For questions, bug reports, or feature requests, please open an issue on the GitHub repository.
- Known Issue -
.tap
interaction is not currently activated. Passing the.tap
will not change the input - Roadmap - increase size of particles for a wider particle path
Pattern Authentication is available under the MIT license. See the LICENSE file for more info.