Hi I have a simple form that allows a user to input a name, their gender and a password. I use Digest::MD5.hexdigest to encrypt the input. Once I have the encrypted input eg, d1c261ede46c1c66b7e873564291ebdc, I want to be able to append this to a file I have already created. However every thing I have tried just isn’t working. Can anyone please help and thank you in advance. Here is what I have:
input = STDIN.read( ENV["CONTENT_LENGHT"] )
puts "Content-type: text/html \n\n"
require 'digest/md5'
digest = Digest::MD5.hexdigest(input)
f = File.open("register.txt", "a")
f.write(digest)
f.close
I have also tried this with no luck:
File.open("register.txt", "a") do |f|
f.puts(digest)
end
If the code is verbatim then I think you have a typo in the first line: did you mean
CONTENT_LENGHTor is it a typo? ENV[] will return a string if the variable is set, which will upsetSTDIN#read. I getTypeError: can't convert String into Integer. Assuming the typo, thenENV[]returnsnil, which tellsSTDIN#readto read until EOF, which from the console means, I think, Control-Z. That might be causing a problem.I suggest you investigate by modifying your script thus:
This works on my machine, with the following output (when CONTENT_LENGTH set to 12):