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

  • SEARCH
  • Home
  • 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 7844707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:58:21+00:00 2026-06-02T16:58:21+00:00

I have a system set up to generate random codes. It creeates hundreds of

  • 0

I have a system set up to generate random codes. It creeates hundreds of thousands of them:

function createRandomPassword() {
    $chars = "abcdefghijklmnopqrstuvwxyz0123456789";

    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;
    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    return $pass;
}

Basically this function is used to loop through and give me my desired number of results. However, its VERY important that nobody can get a handful of these codes and figure a way to predict more of them from a given formula or something. Is this possible with my current system? Or is there a way I can make my current system more secure to prevent people from predicting more of the codeS?

Thanks

  • 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-02T16:58:27+00:00Added an answer on June 2, 2026 at 4:58 pm

    I doubt people can easily predict a way to generate more of those codes, unless they have your php code of course.

    You could store the valid codes in the database and check whether the entered code is one generated by you by checking whether or not it exists in the ‘valid_codes’ table.

    Or….

    What I might do is try to add a verification string to the $pass code, so that you can check, after the user enters the passcode, that the code is indeed a valid code (generated by you).

    For example, this would add a 6-character verification string to the end of $pass:

    function createRandomPassword() {
        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
    
        srand((double)microtime()*1000000);
        $i = 0;
        $pass = '' ;
        while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($chars, $num, 1);
            $pass = $pass . $tmp;
            $i++;
        }
    
        // NEW STUFF HERE
        $salt = 'my_secret_salt';
        // generate an md5 of $pass + our salt
        $verification_md5 = md5($pass . $salt);
        // $verification_code = the first 6 characters of that md5
        $verification_code = substr($verification_md5, 0, 6);
    
        $pass = $pass . $verification_code;
    
        return $pass;
    }
    

    Then, when someone enters your code, you can check whether this is a ‘valid’ code by checking the first 6 characters of the md5() + salt of the code they entered(minus the last 6 characters, of course).

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

Sidebar

Related Questions

I have a system set up to lock certain content in a database table
I have a credit system set up on my site where user A can
I have a user system set up in a 'users' table, and I have
I have a basic messaging system set up and I m using the same
I have a potential client that set up their website and membership system in
How should I set WordWrap = false to a System.Windows.Forms.Label ? I have a
I have installed apache-tomcat-6.0.35-windows-x86 in my system. How can I configure it and set
We have system here that uses Java JNI to call a function in a
I've been trying to set up a system whereby I can generate a series
I have a rating system that uses the following equation to generate the rating

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.