0

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;
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ruby_rocks
0

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.

0

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.

0

@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 }"
0

@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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.