Sending password safely from the front-end to the back-end using MD5
Asked Answered
T

3

23

I've encrypted a password field in my DB by MD5, and I handle it encrypted in my back-end, but when user types their password in, it is in plain text.

Is there a safe way to pass the password from the front-end to the back-end? MD5 doesn´t have sense in this case...

NOTE: I'm using HTTPS and the POST Method.

Tolerate answered 8/6, 2016 at 11:23 Comment(2)
Yes, HTTPS is enough for all resources.Hancock
You should never use a simple hash function to protect your user's passwords. You need to use a strong hashing scheme like PBKDF2, bcrypt, scrypt and Argon2. Be sure to use a high cost factor/iteration count. It is common to choose the cost so that a single iteration takes at least 100ms. See more: How to securely hash passwords?Hancock
A
31

You can think about the following steps to protect the password:

  1. Use HTTPS preferably with HSTS to protect the passwords during transport;

  2. Use a password hash such as bcrypt instead of MD5 to protect the password on the server.

    • HASH passwords with salt;
    • use a high work factor for bcrypt.

MD5 is not the best way to hash. MD5 is not considered secure anymore.

MD5 is not encryption; don't encrypt passwords, hash them, encryption can be decrypted, hashing cannot be reversed.

Avoidance answered 8/6, 2016 at 14:10 Comment(3)
Thanks Tom. Yep, I´m speaking about hearsay but I´m pretty sure I read something about MD5 was hacked in myspace... So I´m writting down... Bcrypt and if not hash... CheersTolerate
Yes, MD5 not considered sure anymore. And using a salt is a good practice.Avoidance
I've edited this answer substantially, adding a the term work factor. Otherwise it's the same content. Please edit or roll back if you're dissatisfied with my edits.Williamswilliamsburg
M
66

While the accepted answer correctly describes how you should STORE passwords on the server side, the question was actually on how to transmit password safely from client to server.

I just want to make clear that the salting and hashing is done at the server side. The client would just sent the clear text password over a secure connection (HTTPS) to the server.

Morganne answered 8/6, 2016 at 15:39 Comment(7)
You could cheat a bit and let the client do most of the work, only to perform the last part of the hash on the server.Williamswilliamsburg
@MaartenBodewes How would that work exactly? The client does not have access to the salt. Also, you want to have the hashing done at the server side as it prevents the client from distributing the work.Morganne
You can send the client the salt. The client distributing the work is not possible as bcrypt is sequential in nature. But even if it would be then the client distributing the work is not a problem; an attacker could distribute the work, but that's not the problem in the first place. If required you could keep a pepper at the server side (a secret value). But I must admit that these kind of schemes are not common (if only because it would be dog-slow in JavaScript).Williamswilliamsburg
As are most things in JavaScript. :) You're correct on the hashing being sequential, so distributing is not an issue. However, if the hashing doesn't happen on the server side, the hash becomes the password. An attacker can try to brute force the system by trying out all possible hashes as there's no slow down at the server side anymore.Morganne
You would still have to generate all the hashes first given the salt, and send each one over to the server to verify them. You cannot just iterate over, say, 2^160 hashes. That's kind of the point.Williamswilliamsburg
True, but if you have the salt, you can take a password dictionary and generate hashes for them. This is something you can distribute. Then, you take the generated hashes and try them against the server. As there's no delay, this is a significant advantage over having to try the password dictionary against the server itself, not?Morganne
Easiest way would be an asymmetric encryption of Payload on Client. Sending to Backend. Decrypting the payload with private key (could be also a KMS Server) and then do normal hash verification :)Nonesuch
A
31

You can think about the following steps to protect the password:

  1. Use HTTPS preferably with HSTS to protect the passwords during transport;

  2. Use a password hash such as bcrypt instead of MD5 to protect the password on the server.

    • HASH passwords with salt;
    • use a high work factor for bcrypt.

MD5 is not the best way to hash. MD5 is not considered secure anymore.

MD5 is not encryption; don't encrypt passwords, hash them, encryption can be decrypted, hashing cannot be reversed.

Avoidance answered 8/6, 2016 at 14:10 Comment(3)
Thanks Tom. Yep, I´m speaking about hearsay but I´m pretty sure I read something about MD5 was hacked in myspace... So I´m writting down... Bcrypt and if not hash... CheersTolerate
Yes, MD5 not considered sure anymore. And using a salt is a good practice.Avoidance
I've edited this answer substantially, adding a the term work factor. Otherwise it's the same content. Please edit or roll back if you're dissatisfied with my edits.Williamswilliamsburg
S
1

Passwords in database must be hashed and kept to secure user's account in case of any unfortunate database leak or hack. But this does not secure the data passed on the network from frontend to backend. For the same using HTTPS helps to encrypt all data passing on the network.

Synonym answered 22/3, 2021 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.