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 8803819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:26:27+00:00 2026-06-14T01:26:27+00:00

I have two fields in login table password salt And I have this little

  • 0

I have two fields in login table

  • password
  • salt

And I have this little function to generate salt

function random_salt($h_algo="sha512"){
        $salt1=uniqid(rand(),TRUE);
        $salt2=date("YmdHis").microtime(true);
        if(function_exists('dechex')){
            $salt2=dechex($salt2);
        }
        $salt3=$_SERVER['REMOTE_ADDR'];
        $salt=$salt1.$salt2.$salt3; 

        if(function_exists('hash')){
            $hash=(in_array($h_algo,hash_algos()))?$h_algo:"sha512";
            $randomsalt=hash($hash,md5($salt)); //returns 128 character long hash if sha512 algorithm is used.
        }else{
            $randomsalt=sha1(md5($salt)); //returns 40 characters long hash
        }

        return $randomsalt;
    }

Now to create user password I have following

$userinput=$_POST["password"] //don't bother about escaping, i have done it in my real project.
$static_salt="THIS-3434-95456-IS-RANDOM-27883478274-SALT"; //some static hard to predict secret salt.
$salt=random_salt(); //generates 128 character long hash.
$password =sha1($salt.$userinput.$static_salt);

$salt is saved in salt field of database and $password is saved in password field.

My problem, In function random_salt(), I m having this FEELING that I’m just making things complicated while this may not generate secure salt as it should. Can someone throw me a light whether I m going in a right direction?

P.S. I do have an idea about crypt functions and like such. Just want to know is my code okay?

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-14T01:26:28+00:00Added an answer on June 14, 2026 at 1:26 am

    This is obviously a security problem:

    uniqid(rand(),TRUE);
    

    How did you set the seed for rand().? Where is you entropy pool?
    As long as you can’t answer the salt has to be considered predictable. Remember: security doesn’t come from code obscurity.

    If you choose a good PRNG all the other salts (e.g. server name, static long salt, time etc..) become irrilevant.

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

Sidebar

Related Questions

I have a usual login form consisting of two input fields, one for login,
I have two tables. The 'Store' table is a demographics table, with fields like
I have two TIMESTAMP fields in my user table that I want to update
I have a table with two fields in an sql server database and my
I have a table named Users , where I have two fields username and
I have two fields on the form ( forgotpassword form ) username and email
I have two fields in separate linked tables with the same data, but different
I have two fields on my web page ie: BookAuthor and BookDescription.On submit,the page
I have two fields - amount (decimal (11, 2)) - gift_amount (decimal (11, 2))
I have two fields that need to multiply each other and fill a third

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.