Prevent unauthorized access to administrative credentials
defmodule MyApp.Cache do
def store_credentials(username, password) do
:ets.new(:creds, [:public, :named_table])
:ets.insert(:creds, {username, password})
end
end
In the below code, admin credentials are stored directly into the Elixir's ETS (Erlang Term Storage) which acts as in-memory store. If an attacker manages to dump the ETS table, they can gain access to sensitive data.
defmodule MyApp.Cache do
def store_credentials(username, password) do
hashed_password = Bcrypt.hashpwsalt(password)
:ets.new(:creds, [:public, :named_table])
:ets.insert(:creds, {username, hashed_password})
end
end
In the below secure code, the admin credentials are hashed before being stored into the ETS. This means even if an attacker dumps the ETS table, they cannot gain access to the actual admin credentials.