Check credentials and create a session
This commit is contained in:
1 parent
8a8d793199
commit
d61c137c12
3 files changed
+53
-9
No files matched your search
+6
-6
@@ -5,6 +5,9 @@ require "fileutils"
|
||||
require "io/console"
|
||||
require "securerandom"
|
||||
|
||||
DATA_DIR = File.join(__dir__, "../data")
|
||||
USER_FILE = File.join(DATA_DIR, "user.txt")
|
||||
|
||||
print "User name: "
|
||||
username = $stdin.gets.chomp
|
||||
|
||||
@@ -16,14 +19,11 @@ end
|
||||
print "Password: "
|
||||
password = $stdin.noecho(&:gets).chomp
|
||||
|
||||
user_path = File.join(File.dirname(__FILE__), "../user.txt")
|
||||
|
||||
salt = SecureRandom.random_bytes(8)
|
||||
salthex = salt.chars.map {|c| sprintf("%02X", c.ord)}.join
|
||||
salt = SecureRandom.hex(8)
|
||||
input = salt + password
|
||||
hash = Digest::SHA256.hexdigest(input)
|
||||
hashhex = hash.chars.map {|c| sprintf("%02X", c.ord)}.join
|
||||
user_file_contents = "#{username}:#{salthex}:#{hashhex}\n"
|
||||
user_file_contents = "#{username}:#{salt}:#{hashhex}\n"
|
||||
|
||||
File.binwrite(user_path, user_file_contents)
|
||||
File.binwrite(USER_FILE, user_file_contents)
|
||||
puts "User and password set"
|
||||
Reference in new issue
Block a user