updated readme to match latest api

This commit is contained in:
Aravinth Manivannan 2021-03-04 20:51:06 +05:30
parent 769bf21c61
commit ffe66b007d
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 50 additions and 43 deletions

View file

@ -35,57 +35,61 @@ argon2-creds = { version = "0.1", git = "https://github.com/realaravinth/argon2-
implementation for the default configuration.
```rust
use argon2_creds::Config;
use argon2_creds::Config;
fn main() {
let config = Config::default();
fn main() {
let config = Config::default();
let password = "ironmansucks";
let hash = config.password(password).unwrap();
let password = "ironmansucks";
// 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();
// email validation
config.email(Some("batman@we.net")).unwrap();
assert_eq!(username, "realaravinth");
assert!(Config::verify(&hash, password).unwrap(), "verify hahsing");
}
```
// 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");
}
```
2. To gain fine-grained control over how credentials are managed, consider using
[ConfigBuilder]:
```rust
use argon2_creds::{ConfigBuilder, Config};
use argon2_creds::{Config, ConfigBuilder, PasswordPolicyBuilder};
fn main() {
let config = ConfigBuilder::default()
.salt_length(32)
.username_case_mapped(false)
.profanity(true)
.blacklist(false)
.argon2(argon2::Config::default())
.build()
.unwrap();
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();
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();
// email validation
config.email(Some("batman@we.net")).unwrap();
assert_eq!(username, "realaravinth");
assert!(Config::verify(&hash, password).unwrap(), "verify hahsing");
}
// 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");
}
```

View file

@ -1,4 +1,6 @@
//To gain fine-grained control over how credentials are managed, consider using ConfigBuilder:
/* To gain fine-grained control over how credentials are managed,
* consider using ConfigBuilder:
*/
use argon2_creds::{Config, ConfigBuilder, PasswordPolicyBuilder};

View file

@ -1,5 +1,6 @@
// The easiest way to use this crate is with the default configuration. See `Default`
// implementation for the default configuration.
/* The easiest way to use this crate is with the default configuration.
* See `Default` implementation for the default configuration.
*/
use argon2_creds::Config;