Skip to content

Commit

Permalink
[PM-3434] Password generator (#261)
Browse files Browse the repository at this point in the history
## Type of change
```
- [ ] Bug fix
- [x] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective
Implement password generation
The `min_` fields were set to bool incorrectly I assume, so I changed
them to u8.

At the moment if all the minimums turn out larger than the length, I
just expand the length, but that seems wrong. I feel like it would be
best to return an error in that case instead of changing any values
behind the user, thoughts?
  • Loading branch information
dani-garcia authored Dec 5, 2023
1 parent f684cc9 commit c006cbb
Show file tree
Hide file tree
Showing 3 changed files with 401 additions and 18 deletions.
21 changes: 21 additions & 0 deletions crates/bitwarden/src/tool/generators/client_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ pub struct ClientGenerator<'a> {
}

impl<'a> ClientGenerator<'a> {
/// Generates a random password.
///
/// The character sets and password length can be customized using the `input` parameter.
///
/// # Examples
///
/// ```
/// use bitwarden::{Client, tool::PasswordGeneratorRequest, error::Result};
/// async fn test() -> Result<()> {
/// let input = PasswordGeneratorRequest {
/// lowercase: true,
/// uppercase: true,
/// numbers: true,
/// length: 20,
/// ..Default::default()
/// };
/// let password = Client::new(None).generator().password(input).await.unwrap();
/// println!("{}", password);
/// Ok(())
/// }
/// ```
pub async fn password(&self, input: PasswordGeneratorRequest) -> Result<String> {
password(input)
}
Expand Down
Loading

0 comments on commit c006cbb

Please sign in to comment.