2021-01-02 12:46:20 +05:30
|
|
|
<div align="center">
|
|
|
|
<h1>Argon2-Creds</h1>
|
|
|
|
<p>
|
2021-01-29 11:42:59 +05:30
|
|
|
<strong>Argon2-Creds - convenient abstractions for managing credentials</strong>
|
2021-01-02 12:46:20 +05:30
|
|
|
</p>
|
2021-01-02 12:50:15 +05:30
|
|
|
|
2023-10-14 17:20:58 +05:30
|
|
|
|
|
|
|
[![Documentation](https://img.shields.io/badge/docs-v0.2-3)](https://docs.rs/argon2_creds)
|
2023-10-14 16:38:56 +05:30
|
|
|
[![status-badge](https://ci.batsense.net/api/badges/97/status.svg)](https://ci.batsense.net/repos/97)
|
|
|
|
[![dependency status](https://deps.rs/repo/gitea/git.batsense.net/realaravinth/argon2-creds/status.svg)](https://deps.rs/repo/gitea/git.batsense.net/realaravinth/argon2-creds)
|
2021-01-02 12:46:20 +05:30
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2021-01-02 12:50:15 +05:30
|
|
|
## Features
|
2021-12-17 10:42:22 +05:30
|
|
|
|
|
|
|
- [x] PRECIS Framework [UsernameCaseMapped](https://tools.ietf.org/html/rfc8265#page-7)
|
|
|
|
- [x] Password hashing and validation using
|
|
|
|
[rust-argon2](https://crates.io/crates/rust-argon2)
|
|
|
|
- [x] Filters for words that might cause ambiguity. See
|
|
|
|
[Blacklist](https://github.com/shuttlecraft/The-Big-Username-Blacklist)
|
|
|
|
- [x] Profanity filter
|
|
|
|
- [x] Email validation(Regex validation not verification)
|
2021-01-29 11:42:59 +05:30
|
|
|
|
|
|
|
## Usage:
|
|
|
|
|
|
|
|
Add this to your `Cargo.toml`:
|
|
|
|
|
|
|
|
```toml
|
2021-12-17 10:42:22 +05:30
|
|
|
argon2-creds = "0.2"
|
2021-01-29 11:42:59 +05:30
|
|
|
```
|
|
|
|
|
|
|
|
## Examples:
|
|
|
|
|
|
|
|
1. The easiest way to use this crate is with the default configuration. See `Default`
|
2021-12-17 10:42:22 +05:30
|
|
|
implementation for the default configuration.
|
2021-01-29 11:42:59 +05:30
|
|
|
|
2021-12-17 10:42:22 +05:30
|
|
|
```rust
|
2021-03-04 20:51:06 +05:30
|
|
|
use argon2_creds::Config;
|
2021-01-29 11:42:59 +05:30
|
|
|
|
2021-03-04 20:51:06 +05:30
|
|
|
fn main() {
|
2021-12-17 10:42:22 +05:30
|
|
|
let config = Config::default();
|
2021-01-29 11:42:59 +05:30
|
|
|
|
2021-12-17 10:42:22 +05:30
|
|
|
let password = "ironmansucks";
|
2021-01-29 11:42:59 +05:30
|
|
|
|
2021-12-17 10:42:22 +05:30
|
|
|
// email validation
|
|
|
|
config.email(Some("batman@we.net")).unwrap();
|
2021-01-29 11:42:59 +05:30
|
|
|
|
2021-12-17 10:42:22 +05:30
|
|
|
// process username
|
|
|
|
let username = config.username("Realaravinth").unwrap(); // process username
|
2021-03-04 20:51:06 +05:30
|
|
|
|
2021-12-17 10:42:22 +05:30
|
|
|
// generate hash
|
|
|
|
let hash = config.password(password).unwrap();
|
2021-03-04 20:51:06 +05:30
|
|
|
|
2021-12-17 10:42:22 +05:30
|
|
|
assert_eq!(username, "realaravinth");
|
|
|
|
assert!(Config::verify(&hash, password).unwrap(), "verify hashing");
|
2021-03-04 20:51:06 +05:30
|
|
|
}
|
|
|
|
```
|
2021-01-29 11:42:59 +05:30
|
|
|
|
|
|
|
2. To gain fine-grained control over how credentials are managed, consider using
|
2021-12-17 10:42:22 +05:30
|
|
|
[ConfigBuilder]:
|
2021-01-29 11:42:59 +05:30
|
|
|
|
|
|
|
```rust
|
2021-03-04 20:51:06 +05:30
|
|
|
use argon2_creds::{Config, ConfigBuilder, PasswordPolicyBuilder};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let config = ConfigBuilder::default()
|
|
|
|
.username_case_mapped(false)
|
|
|
|
.profanity(true)
|
|
|
|
.blacklist(false)
|
|
|
|
.password_policy(
|
|
|
|
PasswordPolicyBuilder::default()
|
|
|
|
.min(12)
|
|
|
|
.max(80)
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let password = "ironmansucks";
|
|
|
|
let hash = config.password(password).unwrap();
|
|
|
|
|
|
|
|
// email validation
|
|
|
|
config.email(Some("batman@we.net")).unwrap();
|
|
|
|
|
|
|
|
// process username
|
|
|
|
let username = config.username("Realaravinth").unwrap(); // process username
|
|
|
|
|
|
|
|
// generate hash
|
|
|
|
let hash = config.password(password).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(username, "realaravinth");
|
2021-12-17 10:42:22 +05:30
|
|
|
assert!(Config::verify(&hash, password).unwrap(), "verify hashing");
|
2021-03-04 20:51:06 +05:30
|
|
|
}
|
2021-01-29 11:42:59 +05:30
|
|
|
```
|