I need to replicate the encryption shown below:

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

I am trying something like this to no avail:

$salt = 'edc93eaf81aa1d64368c35213f192bb4ea81d20d';
$password = $_POST['input'];
$password = sha1($salt.$password);
		
echo "password sha1 value: " . $password;

Or even if anyone could help me with what "--#" and "--" means in ruby it would help loads. I'm assuming that anything wrapped in curly brackets '{}' is a variable.

I need to replicate the encryption shown below:

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

I am trying something like this to no avail:

$salt = 'edc93eaf81aa1d64368c35213f192bb4ea81d20d';
$password = $_POST['input'];
$password = sha1($salt.$password);
		
echo "password sha1 value: " . $password;

Ruby on rails has a built in method and if I remember it correctly it is self.salt . You can always google ruby on rails salt if you'd like.

@xylude, In response to your question about what -- and #{} mean in Ruby, in your example those hyphens or dashes are just part of a string. "--" is just two hyphens, not ruby code. The important part is in the #{}. The pound sign followed by curly braces is used for interpolating variables and evaluating expressions within strings. E.g.

var1 = "some string"
var2 = "String then interpolating a variable #{ var1 }"

In addition to interpolating variables, you can also evaluate expressions inside the #{ }. E.g.

var = "some string"
expression_in_string = "Var reversed: #{ var.reverse}, now in caps: #{ var.upcase }"

@xylude, what exactly is failing in your php code? It works fine for me using the php -a interactive shell on Macbook Pro, Leopard. Maybe try pasting your entire php function code into the thread?

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.