Generate a salt - RMB Scripting
You appear not to have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Affiliates
  Arcade <-- New!
  IoxHost
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Python
  Other
 
Latest Tutorials
RMB User Commenting Sy...
Easy Navigation Integr...
Decorate Basic Icon
paragraph shortner
Convert Email address ...
Latest Comments
Badge System
Pet system
Pet system
Badge System
Report & Warn Script
Stats
Total Members: 597 [241]
Total Tutorials: 284
Newsest User: andrerds
Todays Unique Hits: 116
Users Online: 0
 
7 Guests
Poll
What do you look for in a web host?
Price
Uptime
Reviews
Customer Service
Size of Company
Main Content
Tutorial: Generate a salt By afroxav
Sometimes, there is a need to generate a salt. A salt for any reason at all. Maybe a salt to hash a password, or to generate a key. Well I have a little function/script that can be included in code to generate a salt. The usage is pretty basic: generateSalt($max = 15) where $max is the number of characters to include.

The way that the function works is that it takes a random value between 0 and the number of characters in the list minus one. Since the number is random, it can happen that the same character is included more than once in a salt, which is more random that the php shuffle() function, since each character is independent from the other. This means that the salt could also be longer than the character list.
   
PHP:
<?php

/**
 * This function generates a password salt as a string of x (default = 15) characters
 * ranging from a-zA-Z0-9.
 * @param $max integer The number of characters in the string
 * @author AfroSoft <scripts@afrosoft.co.cc>
 */
function generateSalt($max 15) {
    
$characterList "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    
$i 0;
    
$salt "";
    do {
        
$salt .= $characterList{mt_rand(0,strlen($characterList))};
        
$i++;
    } while (
$i <= $max);
    return 
$salt;
}

?>

Difficulty: Easy
Views: 137
Rating:
Comments
There are currently no comments for this tutorial.
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Evening Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
$2.50 Resellers
Free Domains
Free Games
Affiliates