Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

TENX-S/rand_key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random key generator

USE AS YOUR OWN RISK

What

Generate random keys in handy way.

Why

To learn Rust.

Requirement

Rust 1.39 or higher.

Try it

$ 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

Usage

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(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Contribution

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.

About

Generate random keys in handy way

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages