Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would this be a secure way to store passwords in a database? #4535

Open
2 tasks done
AlexDiego123 opened this issue Jan 19, 2025 · 1 comment
Open
2 tasks done

Would this be a secure way to store passwords in a database? #4535

AlexDiego123 opened this issue Jan 19, 2025 · 1 comment

Comments

@AlexDiego123
Copy link

AlexDiego123 commented Jan 19, 2025

Node.js Version

v22.13.0

NPM Version

v11.0.0

Operating System

Windows 10 22H2 (Build 19045.5371)

Subsystem

crypto

Description

Hey, i was searching a good way to store passwords/private data in a database using hashing, would this be a secure way?

const crypto = require('crypto');
const randomSalt = crypto.randomBytes(64).toString('hex'); //generate an unique salt for every password

const data = "hello world"
const saltedData = data + randomSalt;

const hash = crypto.createHash('sha3-512');
hash.update(saltedData);
const hashedData = hash.digest('hex');

//then store hashedData in a database

Minimal Reproduction

  1. Run the code above

Output

No response

Before You Submit

  • I have looked for issues that already exist before submitting this
  • My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask
@gireeshpunathil
Copy link
Member

if you use a hash function based on random value, it may be too secure to be able to decrypt it! how you plan to retrieve the password later?

the usual practice IMO is to use:

  • asymmetric encryption for data that moves across n/w
  • symmetric ones for data at rest (storing in your own device)
  • hash functions if you only want to store a mirror of the data (no un-hashing possible)

caveat: I am not an expert in this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants