wolfiton

wolfiton

Hello everyone,

Today I would like to ask for your help on authorization and authentication

So at the moment i have the following migration

defmodule PhxApi.Repo.Migrations.CreateUsers do
  use Ecto.Migration

  def change do
    create table(:users) do
      add :username, :string
      add :email, :string
      add :password_hash, :text
      add :role, :string
      add :confirmed, :boolean
      add :attempts, :integer
      add :locked, :boolean

      timestamps()
    end


    create unique_index(:users, [:email])
    create unique_index(:users, [:username])
  end
end

The following migration is used to take into account the following scenarios:

  • User
    • registration
    • login
    • account confirmation
    • user block by username and email

What would you add more to this migration and in general to take into account other security scenarios?

Also how you deal with users ip where would you store them?

Would you use ETS or mnesia for account confirmation?

Also other suggestions or you person experiences are welcomed
Thanks in advance

Showing Posts 1 to 10

LostKobrakai

LostKobrakai

I’d take a look at Pow or phauxth and how they handle things.

Why would you want to store IPs in the database?

I’m wondering why :attempts is a string. Sounds like it should be an integer.
Also while you have a confirmed field I’d additionally propose to separate email from unconfirmed_email, so on a change you don’t loose the already confirmed email until the new one is confirmed as well.

wolfiton

wolfiton OP

Where would you recommend storing the ips?

You are right it should be a integer

Also very cool suggestion by using the unconfirmed_email and the confirmed_email strategy to have both

Thanks for providing your thoughts and ideas on this matter.

LostKobrakai

LostKobrakai

Depends on why you want to store them.

Based on prev. conversations in another topic of yours: If you want to pin sessions to IPs, then it’s only natural to put the IP in the session itself. It will neatly cleanup after itself.

wolfiton

wolfiton OP

Yes but thinking a little bit about attacks and user behavior wouldn’t it be a good idea to store them also somewhere else for the following case:

  • A non logged in user(bot or human) makes multiple requests just to generate a ddos(DENIAL OF SERVICE ATTACK) attack how can i stop it if they are not logged in?
thojanssens1

thojanssens1

Can you explain your idea please? (I’m still quite new)
Why do you need some kind of store in addition to the db for account confirmation?

LostKobrakai

LostKobrakai

This is a valid use-case for storing an IP for a bit longer timeframe, possibly in a db, but this has nothing to do with a users table though. This would at least live in a totally separate part/table of your application. Generally I’d also suggest to move prevention of such attacks up the stack and use e.g. fail2ban or similar software or do it even at the dns level with cloudflare. This way your application(s) don’t need to deal with those issues.

wolfiton

wolfiton OP

Mensia and ets are databases that are using the ram of the server so they are much faster for read and delete then a normal db.

Redis is a good example of this.

Also because you need the confirmation token which is basically a secret string to verify if the user that clicked the link form the email you sent for the account confirmation, is who it pretends to be and not someone else that wants to take control over another users account.

This idea is used for the confirmation of the account also if a user forgets a password.

If what i wrote is unclear please tell me and i will try to explain in another way.

LostKobrakai

LostKobrakai

Why would you want to use ets or mnesia for that information though? Either the token can validate itself (signed token) or you need a persistent db, which you already have with ecto.

wolfiton

wolfiton OP

In the past I used redis because those tokens don’t have a very long existence they are only necessary for that verification also they need to expire in let’s say 15 minutes.
So reading and writting to the db may become expensive.

thojanssens1

thojanssens1

Correct me if I’m wrong, but you did not really explain the reason WHY you want to use mnesia or ets for the account confirmation.

For example: is the reason because you do not want to store that secret token in the database? (security)
is the reason because of some performance optimization? (but then why limit performance optimization for that very specific case?)
etc.

Even if you use the RAM, won’t that create scalability issues (i.e. RAM is not shared among multiple servers) ?

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews