I am somewhat new to ruby (but not to programming) and I want to develop a small web-app with Sinatra. I started creating a small password utility script that hashes and secures entered password. I am not sure it is finished. I would like to know if there are any ruby tricks to make my code better or more verbose, and what else needs to be done / changed to make passwords more secure. Any criticism is appreciated. here is my code:
require 'digest'
def random_salt
hash = ''
for i in 1..64
rand_seed = rand(0..61)
hash << 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'[rand_seed]
end
return hash
end
# password format: salt + password + length_of_salt_and_hash
def hash_password(password)
salt = random_salt
hashed_pass = Digest::SHA512.hexdigest password.chomp
length = salt.length + hashed_pass.length
return salt + hashed_pass + length.to_s
end
# just a test
print 'Enter a password: '
word = gets
new_word = hash_password word
puts new_word