diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b1eb688 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +## 0.2.1 + +### Changed: + +-`Config::email` now takes a `&str` instead of `Option<&str>` + +## 0.2.0 + +### Added + +- minimum and maximum password length + +## 0.1.0 + +### Added: + +- password configuration +- UsernameCaseMapped filter +- Abusive words filter +- filter for words that might cause security issues diff --git a/Cargo.toml b/Cargo.toml index 627c452..fb003d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,4 +26,4 @@ validator = { version = "0.13.0", features = ["derive"]} lazy_static = "1.4.0" regex = { version = "1.3.9", features = [ "perf-inline", "perf-dfa", "perf-literal", "perf-cache", "perf"]} rand = "0.8.0" -derive_builder = "0.9" +derive_builder = "0.10" diff --git a/examples/complex.rs b/examples/complex.rs index 4ee772c..f8a35b7 100644 --- a/examples/complex.rs +++ b/examples/complex.rs @@ -23,7 +23,7 @@ fn main() { let hash = config.password(password).unwrap(); // email validation - config.email(Some("batman@we.net")).unwrap(); + config.email("batman@we.net").unwrap(); // process username let username = config.username("Realaravinth").unwrap(); // process username diff --git a/examples/simple.rs b/examples/simple.rs index 2dc28a4..0d3d8dd 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -10,7 +10,7 @@ fn main() { let password = "ironmansucks"; // email validation - config.email(Some("batman@we.net")).unwrap(); + config.email("batman@we.net").unwrap(); // process username let username = config.username("Realaravinth").unwrap(); // process username diff --git a/src/config.rs b/src/config.rs index 8b6922c..f471328 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,9 +56,9 @@ impl Default for PasswordPolicy { } #[derive(Validate)] -struct Email { +struct Email<'a> { #[validate(email)] - pub email: String, + pub email: &'a str, } impl Default for Config { @@ -84,14 +84,11 @@ impl Config { } /// Checks if input is an email - pub fn email(&self, email: Option<&str>) -> CredsResult<()> { - if let Some(email) = email { - let email = Email { - email: email.trim().to_owned(), - }; - email.validate()?; - } - Ok(()) + pub fn email(&self, email: &str) -> CredsResult<()> { + let email = Email { + email: email.trim(), + }; + Ok(email.validate()?) } fn validate_username(&self, username: &str) -> CredsResult<()> { @@ -179,10 +176,7 @@ mod tests { .build() .unwrap(); - assert_eq!( - config.email(Some("sdfasdf".into())), - Err(CredsError::NotAnEmail) - ); + assert_eq!(config.email("sdfasdf".into()), Err(CredsError::NotAnEmail)); } #[test] @@ -190,7 +184,7 @@ mod tests { let password = "somepassword"; let config = Config::default(); - config.email(Some("batman@we.net")).unwrap(); + config.email("batman@we.net").unwrap(); let username = config.username("Realaravinth").unwrap(); let hash = config.password(password).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index b13a3a1..3da85b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! let hash = config.password(password).unwrap(); //! //! // email validation -//! config.email(Some("batman@we.net")).unwrap(); +//! config.email("batman@we.net").unwrap(); //! //! // process username //! let username = config.username("Realaravinth").unwrap(); // process username @@ -48,7 +48,7 @@ //! let hash = config.password(password).unwrap(); //! //! // email validation -//! config.email(Some("batman@we.net")).unwrap(); +//! config.email("batman@we.net").unwrap(); //! //! // process username //! let username = config.username("Realaravinth").unwrap(); // process username