jdumont

jdumont

Hey all,

I’ve been learning event sourcing with Commanded lately and wanted to double-check when to hash a password — I think I already know the answer though!

I have an Accounts context with User and Credential aggregates. The RegisterUser command is passed the users name, email address and plain-text password. The User aggregate only handles their name, with email and password heading to the Credential.

I had originally planned to hash the password in the CreateCrendential command, as that seems the most logical place. However, because the CreateCrendential command is triggered by the UserRegistered event, that would mean that the unhashed password would get serialised into that event — obviously a big no-no!

That leaves me with two options:

  1. Hash the password as soon as it hits my system, which at the moment would be in the RegisterUser command.
  2. Change the order. The form submission (or endpoint submission) issues the CreateCredential command, which hashes the password (more logical place for this to take place) and then the RegisterUser command responds to the CredentialCreated event.

Option 1 feels like a bodge, so I’m inclined to go with option 2. Only issue is that the User UUID is created/assigned in the CreateCredential command, rather than the RegisterUser command. I don’t see this as much of an issue though as both aggregates would store this UUID anyway.

Thoughts? Does changing the order of commands/events make the most sense and avoid storing unhashed passwords in a logical way?

Showing Posts 1 to 10

Fl4m3Ph03n1x

Fl4m3Ph03n1x

When it comes to passwords and security, you want your passwords to be hashed as soon as possible. Having your UI sending an un-encrypted password to your backend for processing is a big no no, as it makes your system vulnerable to man in the middle attacks.

I would personally go for option 2.

Phillipp

Phillipp

Then you loose any ability to validate your password against length and complexity. That, for me, is a big no no. And please, please don’t respond with “client validation”.

NobbZ

NobbZ

He is right, sending unencrypted passwords is a NONO, no one should use HTTP anymore with letsencrypt beein available for free.

But I do support you, in the regard, that one should not hash client side. This will not only make you loose the validation opportunities as you say, but it will basically leak the hashing secret…

Or even worse, the hash itself becomes volatile as a plain text password, and an attacker that gains access to the database gains access to all user accounts.

Phillipp

Phillipp

Hashing client side means, that the hash is the “new password” and a MITM attack would just work fine. All ya need is the hash then.

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Frontend validation also has its issues (I’ll give you that), as it can easily be bypassed. I picked option 2 because from reading the question I understood I could only pick 1 or 2. But it really does depend on the case. If your UI is talking to a public REST API, you may want to have it in both places.

If your app is being used inside a company within their private intranet, UI validation is likely good enough.

It all comes down where you want your validation to happen - sometimes you may even want validation on both sides:

Phillipp

Phillipp

The UI has to communicate somehow with the backend and at some point, something is being sent to the server. If it’s the user-entered password or the generated hash, doesn’t matter since a MITM attack works for both.

Fl4m3Ph03n1x

Fl4m3Ph03n1x

I just edited my post to remove that comment. It figures your typing skills would superseed mine xD

LostKobrakai

LostKobrakai

I’m actually wondering how this went to a client/server side discussion. The initial poster asked about eventsourcing and how to structure password hashing in an event sources system without storing the pw in an event. There’s no “client” involved at that stage. It’s all server side.

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Likely my fault, since I miss understood the question and then directed the topic in the wrong direction from that point forward =(

I will show myself out.

Phillipp

Phillipp

And I got triggered. So, lets agree on 50/50.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
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
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews