Goal:
Obtain the database password from the user in order to avoid hardcoding it in the config file. What’s the safest, most efficient way of accomplishing this?
#My_appDB_Credentials
defmodule My_appDB_Credentials do
# def validate_entry(password_length, password) when password_length == 15, do: String.trim(password)
def validate_entry(password_length, password) when password_length == 15 do
String.trim(password)
|> System.put_env("db_password", password)
end
def validate_entry(_, _) do
Print.error("Incorrect password. Try again.")
get_database_password()
end
def process_password_string_input() do
password = request_password()
String.length(password)
|> validate_entry(password)
end
def request_password() do
IO.gets("Enter database password: ")
end
def get_database_password(), do: process_passwordstring_input()
end
12:20:04.563 [error] GenServer #PID<0.668.0> terminating
** (RuntimeError) connect raised KeyError exception: key :password not found. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
(elixir 1.11.2) lib/keyword.ex:420: Keyword.fetch!/2
(postgrex 0.15.7) lib/postgrex/protocol.ex:722: Postgrex.Protocol.auth_md5/4
(postgrex 0.15.7) lib/postgrex/protocol.ex:579: Postgrex.Protocol.handshake/2
(db_connection 2.3.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
(connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol