943,096 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Unsolved
  • Views: 3219
  • Ruby RSS
Jan 29th, 2010
0

I need a php equivalent to digest::sha1.hexdigest

Expand Post »
I need to replicate the encryption shown below:
Ruby Syntax (Toggle Plain Text)
  1. def self.encrypt(password, salt)
  2. Digest::SHA1.hexdigest("--#{salt}--#{password}--")
  3. end

I am trying something like this to no avail:

Ruby Syntax (Toggle Plain Text)
  1. $salt = 'edc93eaf81aa1d64368c35213f192bb4ea81d20d';
  2. $password = $_POST['input'];
  3. $password = sha1($salt.$password);
  4.  
  5. echo "password sha1 value: " . $password;
Similar Threads
Reputation Points: 13
Solved Threads: 11
Junior Poster
xylude is offline Offline
122 posts
since May 2008
Jan 29th, 2010
0
Re: I need a php equivalent to digest::sha1.hexdigest
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.
Reputation Points: 13
Solved Threads: 11
Junior Poster
xylude is offline Offline
122 posts
since May 2008
Feb 13th, 2010
0
Re: I need a php equivalent to digest::sha1.hexdigest
Click to Expand / Collapse  Quote originally posted by xylude ...
I need to replicate the encryption shown below:
Ruby Syntax (Toggle Plain Text)
  1. def self.encrypt(password, salt)
  2. Digest::SHA1.hexdigest("--#{salt}--#{password}--")
  3. end

I am trying something like this to no avail:

Ruby Syntax (Toggle Plain Text)
  1. $salt = 'edc93eaf81aa1d64368c35213f192bb4ea81d20d';
  2. $password = $_POST['input'];
  3. $password = sha1($salt.$password);
  4.  
  5. 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.
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Feb 15th, 2010
0
Re: I need a php equivalent to digest::sha1.hexdigest
@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.
ruby Syntax (Toggle Plain Text)
  1. var1 = "some string"
  2. var2 = "String then interpolating a variable #{ var1 }"
In addition to interpolating variables, you can also evaluate expressions inside the #{ }. E.g.
ruby Syntax (Toggle Plain Text)
  1. var = "some string"
  2. expression_in_string = "Var reversed: #{ var.reverse}, now in caps: #{ var.upcase }"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ruby_rocks is offline Offline
2 posts
since Feb 2010
Feb 15th, 2010
0
Re: I need a php equivalent to digest::sha1.hexdigest
@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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ruby_rocks is offline Offline
2 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: Rdoc - When and why does it choose to ignore code?
Next Thread in Ruby Forum Timeline: Need help writing a method!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC