USE AS YOUR OWN RISK
Generate random keys in handy way.
To learn Rust.
Rust 1.39 or higher.
$ git clone https://github.com/TENX-S/rand_key
$ cd rand_key
# Default case: amount of letters: 10, symbols: 2, numbers: 3
$ cargo run --release --example kg_test
# Specify the parameter: amount of letters: 16, symbols: 2, numbers: 3
$ cargo run --release --example kg_test 16 2 3
# Try a larger number!
$ cargo run --release --example kg_test 200000 200 300
# Larger and set the unit value
$ cargo run --release --example kg_test 100000000 0 0 100000
In Cargo.toml
:
rand_pwd = "1" # Deprecated
The latest version:
rand_key = { git = "https://github.com/TENX-S/rand_key", branch = "master" }
Here's a simple demo:
use rand_key::{RandKey, ToRandKey};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let r_p = RandKey::new("10", "2", "3")?; // For now, it's empty. Use method `join` to generate the key
r_p.join()?; // Now `r_p` has some content, be kept in its `key` field
println!("{}", r_p); // Print it on the screen
// One possible output: 7$pA7yMCw=2DPGN
// You can also use the method `to_randkey` to convert a `String` or `&str` to `RandPwd`
let r_p = "n4jpstv$dI,.z'K".to_randkey()?;
// You can re-generate a random key and with equivalent amount of letters, symbols and numbers. Like below:
r_p.join()?;
println!("{}", r_p);
// One possible output: qS`Xlyhpmg~"V8[
// But you have to make sure that they were composed of ASCII characters or it will return `Err`.
assert!("🦀️🦀️🦀️".to_randkey().is_err());
Ok(())
}
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.