Opened 12 years ago

Closed 9 years ago

#4183 closed Support Requests (fixed)

Crypto/password generator example

Reported by: olafvdspek@… Owned by: No-Maintainer
Milestone: Boost 1.44.0 Component: random
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

Could you include an example to use the lib to generate a password? I've no idea what generator is best for this purpose and how to seed it properly and I think this is a common practise for this lib.

Change History (6)

comment:1 by Steven Watanabe, 12 years ago

The only choice if you need security is random_device.

comment:2 by Steven Watanabe, 12 years ago

#include <boost/nondet_random.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random/uniform_int.hpp>

int main() {
    std::string chars(
        "abcdefghijklmnopqrstuvwxyz"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "1234567890"
        "!@#$%^&*()"
        "`~-_=+[{]{\\|;:'\",<.>/?");
    boost::random_device rng;
    boost::variate_generator<boost::random_device&, boost::uniform_int<> >
        gen(rng, boost::uniform_int<>(0, chars.size()));
    for(int i = 0; i < 8; ++i) {
        std::cout << chars[gen()];
    }
    std::cout << std::endl;
}

comment:3 by Steven Watanabe, 12 years ago

Resolution: fixed
Status: newclosed

(In [62629]) Add an example of generating a random password. Fixes #4183

comment:4 by JRSmith73@…, 10 years ago

To whom it may concern:

I believe there is a typographical error within your recommended code password.cpp. Specifically, the last line defining the character string contains two open curly braces { and no close curly brace }. (http://www.boost.org/doc/libs/1_50_0/libs/random/example/password.cpp):

"`~-_=+[{]{\\|;:'\",<.>/? ");

I believe the correct entry should be:

"`~-_=+[{]}\\|;:'\",<.>/? ");

However, the impact of this on random password generation is minimal.

Respectfully,

JRSmith

comment:5 by Steven Watanabe, 10 years ago

Resolution: fixed
Status: closedreopened

It's really better to file a new ticket instead of tacking this onto an existing (closed) ticket. I almost missed this.

comment:6 by Steven Watanabe, 9 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.