Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
532 B
3
Indexable
Never
static std::string verification_code = generate_verification_code(10);

std::string generate_verification_code(size_t length) {
    const char charset[] = "0123456789"
                           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                           "abcdefghijklmnopqrstuvwxyz";
    std::default_random_engine rng(std::random_device{}());
    std::uniform_int_distribution<> dist(0, sizeof(charset) - 2);
    std::string code;
    for (size_t i = 0; i < length; ++i) {
        code += charset[dist(rng)];
    }
    return code;
}
Leave a Comment