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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:19:10+00:00 2026-06-10T07:19:10+00:00

I have a pssword variable where it contains the user’s password which contains some

  • 0

I have a pssword variable where it contains the user’s password which contains some stirngs at the start and end of the password so that it salts the password. Below is the code for this:

$teacherpassword = md5(md5("j92".$teacherpassword."djS"));  

Obviously the characters chosen to salt the password would be the same character for all the passwords.

What I want is to create a random characters generator so that the first 3 characters and the last 3 characters of the salt are all random so each password will have a random salt.

Below is the php generator create to pick out characters at random for the salt:

$salt = ""; 
for ($i = 0; $i < 40; $i++) { 
   $salt .= substr(
     "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
     mt_rand(0, 63), 
     1); 
}

My question is that how do I get the generator to pick out 6 random characters for the salt, and then stick 3 of those characters in front of the passowrd and th other 3 at the end of the password?

FOR EXAMPLE:

PASSWORD 1 could be: $teacherpassword = md5(md5(“jfs”.$teacherpassword.”sfS”));
PASSWORD 2 could be: $teacherpassword = md5(md5(“4f3″.$teacherpassword.p.S”));
PASSWORD 3 could be: $teacherpassword = md5(md5(“wpw”.$teacherpassword.”qq2″));

As you can see all passwords contain their own salt thanks to the php random generator for the salt

  • 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-10T07:19:11+00:00Added an answer on June 10, 2026 at 7:19 am

    A really simple solution would be to use substr()

    substr — Return part of a string

    $randomSalt = "abcdef";
    
    $preSalt = substr($randomSalt, 0,3); // abc
    $postSalt = substr($randomSalt, 3,3);  // def
    
    $password = md5(md5($preSalt.$teacherpassword.$postSalt));
    

    One more suggestion for you would be to use PHP’s uniqueid() function to generate random salt for your passwords.

    uniqid — Generate a unique ID

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

Sidebar

Related Questions

I have an variable obj defined as follows: {user: {username: AzureDiamond, password: hunter2}} I
I have a login script that verifies a username/password against data in a 'user'
If I have a password variable that is used for remote SSL authentication, is
I have a database package which contains some modules namely student_table and a db
Hi In my spring webapp I have a password variable which I want to
I have a file that takes a variable from the user then prints something,
I have created password protected zip file which has xls file with the help
SO buddies, greetings. I have some password requirements I need to implement and one
I have a User model. I have a Session controller, in which I have
I have a web-site written in ColdFusion that contains both the usual interactive web

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.