Pranam Bhat
How to store password like secret credentials in a Database?

How to store password like secret credentials in a Database?

By Pranam Bhat in Databases & DBA on Jul 08 2022
  • Jayraj Chhaya
    Sep, 2022 10

    Hi,

    If you use a SQL Server than you can use below Query.

    1. INSERT INTO dbo.[User] (LoginName, PasswordHash, FirstName, LastName)
    2. VALUES(@pLogin, HASHBYTES('SHA2_512', @pPassword), @pFirstName, @pLastName)
    3. OR
    4. Declare @Encrypt varbinary(200)
    5. Select @Encrypt = EncryptByPassPhrase('key', 'password' )
    6. Select @Encrypt as Encrypt
    7. Select convert(varchar(100),DecryptByPassPhrase('key',@Encrypt )) as Decrypt

    • 2
  • Salman Mushtaq
    Jul, 2022 27

    Use bcrypt hashing

    STEP 1: USER INPUT PASSWORD

    STEP 2: HASH(PASSWORD)

    STEP 3: STORE IN DATABASE AS HASHED PASSWORD

    STEP 4: VERIFY(PASSWORD, HASHED PASSWORD)

    STEP 5: CHECK STEP 4 RETURN TRUE OR FALSE

    • 2
  • Tuhin Paul
    Feb, 2023 22

    Storing passwords and other sensitive information in a secure way is crucial for protecting user data. Here are some best practices for storing password-like secret credentials in a database:

    1. Hash the password: Storing passwords in plain text is never a good idea, as it makes it easy for attackers to gain access to user accounts. Instead, passwords should be hashed using a secure one-way hashing algorithm such as bcrypt or SHA-256. This ensures that even if an attacker gains access to the database, they cannot easily obtain the passwords.

    2. Use a salt: A salt is a random value that is added to the password before it is hashed. This makes it much harder for attackers to use pre-computed hash tables to crack passwords. The salt should be unique for each user and stored alongside the password hash.

    3. Use a secure database: The database itself should be secure, with access restricted to authorized users only. Use strong passwords for database access and avoid storing sensitive information in plain text files or unencrypted backups.

    4. Limit access to sensitive information: Only those who need access to sensitive information should be given permission. This can be done through user roles or by encrypting the sensitive information using a key that is only available to authorized users.

    • 0
  • RomanJay Almaza
    Aug, 2022 2

    This is amazing! Best fence

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS