Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Adding a SALT to your passwords

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Outer

Established Member
Impact
2
Well, adding SALT's to your passwords are basically an added security type of thing.

Usually people just add them to the back or front of the string or something of the sort. I broke up the password and salt and put them "side" of each other basically.

This script breaks up the md5 32-bit md5 password, adds a random SALT to it if you dont already have a SALT, then combines them and returns a 64-bit virtually unbreakable password (ofc anything can be broken, thats why I said "virtually" :P)

PHP:
<?php
function add_salt ($password, $salt = FALSE)
{
    // The number of characters you want in each piece of the array
    $char_num = 4;
    // The $password variable MUST be md5 BEFORE it is run through the script
    // This splits the string into arrays of 4 characters
    $string = str_split($password, $char_num);

    if ($salt == FALSE)
    {
        // Create your own SALT
        // We use MD5 on this method also to make sure its 32 characters
        // This also makes it EXTREMELY harder to guess!
        $salt = md5(uniqid(rand(), true));
    }
    
    // Now that the SALT is set or was already set, we can now divide the salt and
    //  start alternating entering the data
    $salt = str_split($salt, $char_num);
    
    $i = 0; // set it for the SALT identifier
    foreach ($string AS $part)
    {
        $final_password[] = $part.$salt[$i];
        $i++;
    }
    
    return implode($final_password);
}

$password = add_salt(md5("This is a password"));
echo $password;

?>

When using this with a DB, just add a field in the users table named SALT and insert the SALT when it is created. You will need to add some kind of user identifier with that also
 
1
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
very nice post! thanks for sharing
 
0
Close
Hmmm, this code script can be useful, thanks!
 
0
Close
Before anyone goes and tries this, the function str_split() requires php5.

http://us2.php.net/str_split

PHP:
if (!function_exists('str_split')){
     function str_split($string, $split_length=1){

         if ($split_length < 1){
           return false;
         }

         for ($pos=0, $chunks = array(); $pos < strlen($string); $pos+=$split_length){
           $chunks[] = substr($string, $pos, $split_length);
         }
         return $chunks;
     }
   }
(first post on php.net documentation for str_split)

Just add that to your file before you go and use this on versions of php below 5.

Nice post :)

Cody
 
0
Close
So why not just do

PHP:
$password = md5(sometext.$password);
 
0
Close
axilant said:
Before anyone goes and tries this, the function str_split() requires php5.

http://us2.php.net/str_split

PHP:
if (!function_exists('str_split')){
     function str_split($string, $split_length=1){

         if ($split_length < 1){
           return false;
         }

         for ($pos=0, $chunks = array(); $pos < strlen($string); $pos+=$split_length){
           $chunks[] = substr($string, $pos, $split_length);
         }
         return $chunks;
     }
   }
(first post on php.net documentation for str_split)

Just add that to your file before you go and use this on versions of php below 5.

Nice post :)

Cody

cool, thanks for mentioning that!
 
0
Close
Nice work, ill check it out, maybe use it soon for some things i will be working on :p
 
0
Close
very nice.. thank you :)
 
0
Close
snareklutz said:
So why not just do

PHP:
$password = md5(sometext.$password);

PHP:
$password = md5("sometext".$password;

SALT is random characters. You can do that if you want.

iNod.
 
0
Close
Outer said:
Well, adding SALT's to your passwords are basically an added security type of thi

if you dont already have a SALT, then combines them and returns a 64-bit virtually unbreakable password (ofc anything can be broken, thats why I said "virtually" :P)

a salt does not make a password more unbreakable, it reduces the damage when one is broken as you can't reuse the same attack vectors on multi passwords at the same time.

Also, md5 should no longer be used.
 
0
Close
that's very useful. thank you
 
0
Close
thanks, i might try that. Now i jsut need to work out all about functions.
 
0
Close
theparrot said:
a salt does not make a password more unbreakable, it reduces the damage when one is broken as you can't reuse the same attack vectors on multi passwords at the same time.

Also, md5 should no longer be used.


Agreed. md5 can be cracked. Yep. It can be.

I suggest you all start using sha1 or sha2
http://php.net/sha1
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back