I am remaking a site that was built in RoR, I was wondering if anyone could help me with the SHA1 that they used to encrypt the passwords. How do I add the salt into the encryption in PHP? Here is the rails script:

def self.encrypt(password, salt)
    Digest::SHA1.hexdigest("--#{salt}--#{password}--")
  end

Here is my PHP:

class encryptPassword
	{
		public $pass;
		
		function getEncryptedPw()
			{
				return sha1($this->pass);
			}
	}

Not sure how I add the salt in PHP so that the end result is the same as the one in the RoR script.

Recommended Answers

All 3 Replies

string crypt ( string $str [, string $salt ] )

Doesn't crypt use DES? I need SHA1 and the manual doesn't say anything about using the salt as a parameter...

Member Avatar for diafol

Like this?

$password = mysql_real_escape_string($_POST['password']);
$salt = "your choice of word or whatever";
$mysha1 = sha1($salt . $password);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.