We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

chrisaiv on 10/21/07


Tagged

ruby SHA1 encyption


Versions (?)


Encrypting passwords for a database using one-way hash technique (SHA1)


Published in: Ruby 


Before you save a password to a database, it may make sense to encrypt it. That way when you do some user authentication, you can compare the users submitted password to the one on the database.

  1. #A. Import the SHA1 Method
  2. require "digest/sha1"
  3. #B. Encrypt the Password string
  4. @hash_pass = Digest::SHA1.hexdigest('super password')
  5. #C. Display the encrypted password
  6. puts @hash_pass

Report this snippet 

You need to login to post a comment.