October 2006
Intermediate to advanced
888 pages
16h 55m
English
There are times when we don’t want strings to be immediately legible. For example, passwords should not be stored in plaintext, no matter how tight the file permissions are.
The standard method crypt uses the standard function of the same name to DES-encrypt a string. It takes a “salt” value as a parameter (similar to the seed value for a random number generator). On non-UNIX platforms, this parameter may be different.
A trivial application for this follows, where we ask for a password that Tolkien fans should know:
coded = "hfCghHIE5LAM."
puts "Speak, friend, and enter!"
print "Password: "
password = gets.chop
if password.crypt("hf") == coded
puts "Welcome!"
else
puts "What are you, an orc?"
endIt is worth noting that ...
Read now
Unlock full access