Hi,
I have a very simple and common usecase I'm struggling with. When a
system user is created we need to send an email to him with his login
credentials. In a standard application (one without event sourcing) we
generate a password, we send an email, we hash the value and persist
it. The creator of the user does not know the password and the system
does not store it in a non-hashed form. This way the privacy of the
user is preserved. How is it possible to achieve a similar behavior in
an application that is using event sourcing?
If we publish an event with a prehashed password, we will be unable to
send an email - the event handler will only get a hash. If we publish
an event with a non-hashed password, we will store the non-hashed
version of the password in our event stream. We can, of course,
encrypt the password in the event but this only sweeps the breach of
privacy under the rug.
I can see 2 possible options:
1. Raise an event with hashed password and send the email with non-
hashed password after event is raised inside the same aggregate
method. This will be reliable enough so that if the email does not get
sent for some reason, the command will be retried a few more times.
2. Have a UserCreated event handler generate a password, send a
SetPasswordHash command and an email right after. Again, the event
would get retried a few times if email sending fails.
If we use option 1, we leak things like email sending into the domain.
If we use option 2, we have a "dummy" command that is not part of
ubiquitous language. Both feel like a hack to me and differ only by
whether we actually want the user to get created if email sending
fails or not. Are there any other options before I pick one?
If the password is in an event, it is not temporary. The issue here is
not secure/insecure environment. It is more of a legal/company policy
issue that unhashed passwords should be transient. They are not
transient if they sit in event store....
Passwords shouldn't be mailed, or should be immediately changed after
receiving it by mail if you want to be secure.
This way the privacy of the user is preserved