Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:19:49+00:00 2026-06-06T20:19:49+00:00

for a C++ Web-Server I have to generate session id’s. I thought of using

  • 0

for a C++ Web-Server I have to generate session id’s. I thought of using some kind of random number and hash that with the initial IP address of the session and maybe a timestamp.

Will this yield a reasonable unguessable ID? What would be a good random generator algorithm (most preferable one implemented by boost-random)?

kind regards
Torsten

My solution now looks like:

std::string secure_session_generator::operator()( const char* /* network_connection_name */ )
{
    std::stringstream out;
    out << std::hex << distribution_( generator_ );

    return out.str();
}

with the members are default constructed:

    boost::random::random_device                                        generator_;
    boost::random::uniform_int_distribution< boost::uint_least64_t >    distribution_;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:19:50+00:00Added an answer on June 6, 2026 at 8:19 pm

    You could use the example here: Boost example. Then just increase the size to something more befitting a session id like 64 characters or somethings. That way you don’t have to use computation on hashing or anything, and it’s already readable.

    Or without using boost-random and just using ctime and stdio.h

    string getRandom(int ip)
    {
        srand(time(NULL) + ip + rand());
        stringstream ss;
        for(int i = 0;i < 64;i++)
        {
                int i = rand() % 127;
                while(i < 32)
                        i = rand() % 127;
                ss << char(i);
        }
        return ss.str();
    }
    

    Alternatively, without using an IP, you could just pump back a rand() in place of IP, just make sure you seed srand with something.

    Also, by all means, I am not a cryptographer, so use are your own risk.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my strut2 base web application I have generate xls on server and send
I have some Ruby web apps that use OpenID for authentication and store the
I have seen a web app that generate most of a page's markup by
I have a web server that is dynamically creating various reports in several formats
I've set up Nginx as my main web server and have two Mochiweb based
I have a web server which I do not know what the time zone
I have a web server located in Switzerland and it is intended to serve
I have enabled the Web Server on my Mac OS X (10.5.6) by going
I have a web server which is protected behind http-basic-auth. I've read through the
I currently have a single web server hosting multiple WordPress sites which use W3TC.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.