/
session.cr
33 lines (30 loc) · 1.29 KB
/
session.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ===============================================================================
# FILE: session.cr
# USAGE: Internal
# DESCRIPTION:
# AUTHOR: Lewis E. Bogan
# COMPANY: Earthsea@Home
# CREATED: 2017-12-17 15:17
# COPYRIGHT: (C) 2017 Lewis E. Bogan <lewis.bogan@comcast.net>
# Distributed under terms of the MIT license.
# ===============================================================================
# Defines session methods. **extend self** allows these
# methods to be included in a program (class) and invoked without a namespace
# or just used as a namespace.
module Session
extend self
# Adds new session _credentials_ to config file.
def add_credentials(config_file : String, credentials : String)
File.open(config_file, "a") { |file| file.puts credentials }
end
# Prompts the user for host credentials. This method is typically invoked
# when the credentials are not in the configuration file.
def configure_session : Tuple(Hash(String, String))
conf = {} of String => String
conf["user"] = ask("Enter security name: ")
conf["auth"] = Secrets.gets prompt: "Enter authentication phrase: "
conf["priv"] = Secrets.gets prompt: "Enter privacy phrase: "
conf["crypto"] = ask("Crypto algorithm [AES/DES]: ").upcase
{conf}
end
end