argon2-creds/README.md

96 lines
2.8 KiB
Markdown
Raw Normal View History

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
2021-01-29 10:54:53 +05:30
[![Documentation](https://img.shields.io/badge/docs-master-blue)](https://realaravinth.github.io/argon2-creds/argon2_creds/index.html)
2021-01-02 12:48:41 +05:30
![CI (Linux)](<https://github.com/realaravinth/argon2-creds/workflows/CI%20(Linux)/badge.svg>)
2021-01-02 12:53:35 +05:30
[![dependency status](https://deps.rs/repo/github/realaravinth/argon2-creds/status.svg)](https://deps.rs/repo/github/realaravinth/argon2-creds)
2021-01-02 12:46:20 +05:30
<br />
[![codecov](https://codecov.io/gh/realaravinth/argon2-creds/branch/master/graph/badge.svg)](https://codecov.io/gh/realaravinth/argon2-creds)
</div>
2021-01-02 12:50:15 +05:30
## Features
2021-01-02 12:46:20 +05:30
- [x] PRECIS Framework [UsernameCaseMapped](https://tools.ietf.org/html/rfc8265#page-7)
2021-01-02 12:53:35 +05:30
- [x] Password hashing and validation using
[rust-argon2](https://crates.io/crates/rust-argon2)
2021-01-02 12:46:20 +05:30
- [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
argon2-creds = { version = "0.1", git = "https://github.com/realaravinth/argon2-creds" }
```
## Examples:
1. The easiest way to use this crate is with the default configuration. See `Default`
implementation for the default configuration.
```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() {
let config = Config::default();
2021-01-29 11:42:59 +05:30
2021-03-04 20:51:06 +05:30
let password = "ironmansucks";
2021-01-29 11:42:59 +05:30
2021-03-04 20:51:06 +05:30
// email validation
config.email(Some("batman@we.net")).unwrap();
2021-01-29 11:42:59 +05:30
2021-03-04 20:51:06 +05:30
// process username
let username = config.username("Realaravinth").unwrap(); // process username
// generate hash
let hash = config.password(password).unwrap();
assert_eq!(username, "realaravinth");
assert!(Config::verify(&hash, password).unwrap(), "verify hahsing");
}
```
2021-01-29 11:42:59 +05:30
2. To gain fine-grained control over how credentials are managed, consider using
[ConfigBuilder]:
```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");
assert!(Config::verify(&hash, password).unwrap(), "verify hahsing");
}
2021-01-29 11:42:59 +05:30
```