Hướng dẫn dùng password monster trong PHP

Tìm hiểu khi sử dụng các hàm băm tạo dữ liệu lưu trữ password

Khi lưu trữ password vào CSDL thường sẽ sử dụng các hàm băm khác nhau được hỗ trợ bởi hệ CSDL hoặc ngôn ngữ lập trình [như MD5, SHA1 ...] để tạo dữ liệu mã hóa, dữ liệu mã hóa đó được lưu vào CSDL. Ví dụ:

Nội dung chính

  • Tìm hiểu khi sử dụng các hàm băm tạo dữ liệu lưu trữ password
  • Sử dụng Salt tăng cường an toàn cho mật khẩu
  • How Secure is Your Password?
  • Take the Password Test
  • The Most Common Poor Password Practices
  • Common mistakes and misconceptions
  • What makes a strong password?

$raw_password = 'abc123';
$crypt = md5[$raw_password]; //e99a18c428cb38d5f260853678922e03

Ví dụ trên, đã sử dụng hàm băm của PHP là md5 để mã hóa password abc123, kết quả mã hóa là e99a18c428cb38d5f260853678922e03

Bởi vì hàm băm tạo ra các giá trị không thể dịch ngược [không có thuật toán để giải giá trị hash e99a18c428cb38d5f260853678922e03 là chuỗi abc123, chỉ duy nhất một cách là thử], nên có cảm giác sẽ an toàn. Tuy nhiên với các mật khẩu yếu, nó có thể bị dò ra dựa trên giá trị băm của các mật khẩu phổ biến biết trước. Như trường hợp trên khi thấy e99a18c428cb38d5f260853678922e03 thì đoán được password là abc123. Để khắc phục điều này có thể sử dụng đến salt

Sử dụng Salt tăng cường an toàn cho mật khẩu

Để phức tạp hóa mật khẩu lưu trữ, thì các mật khẩu gốc trước khi mã hóa được nối thêm các chuỗi, các chuỗi thêm này gọi là salt

Ví dụ:

$raw_password = 'abc123';

//Sinh ra chuỗi dài 32 ngẫu nhiên, cũng cần lưu chuỗi này vào một cột trong DB
$salt = random_bytes[32];

//Sử dụng thêm một salt cố định
$staticSalt = 'G4334#';


$crypt = md5[$staticSalt.$raw_password.$salt];

Giờ mật khẩu lưu trữ ở trên phức tạp hơn rất nhiều. Biết được $crypt đoán ra $raw_password là rất khó, kể cả khi là password yếu. Khó mà xây dựng được một từ điển chứa các mã hóa tương ứng với password.

How Secure is Your Password?

Take the Password Test

Tip: Show password:

No Password

Symbols

Numbers

Upper case

Lower case

0 characters containing:

Time to crack your password:

0 second

Your passwords are never stored. Even if they were, we have no idea who you are!

Do you want to find out more about password best practices, cyber risks, and the most common mistake people do when creating password?

The Most Common Poor Password Practices

Strong Passwords Tips and Tricks

Common mistakes and misconceptions

  • Replacing letters with digits and symbols. This technique is well known to hackers so swapping an “E” for a “3” or a “5” for a “$” doesn’t make you much more secure
  • That meeting the minimum requirements for a password makes it strong. By today’s standards, an 8-character password won’t make you very secure
  • That it’s fine to use the same password a lot as long as it’s strong – what if the website is hacked? Do you know how the website stores your password? What if they store it in plaintext?

Guilty

  • Weak practices – storing passwords in the notes field on your phone, does it auto sync to the cloud, iCloud or Dropbox
  • Putting them in a spreadsheet, even password protecting a spreadsheet doesn’t keep the information safe. Check out our blog on this and other security subjects.

What makes a strong password?

A strong password is one that’s either not easily guessed or not easily brute forced. To make it not easily guessed it can’t be a simple word, to make it not easily cracked it needs to be long and complex. Super computers can go through billions of attempts per second to guess a password. Try to make your passwords a minimum of 14 characters.

Passphrase

A passphrase is simply a password, that’s longer, it could be a sentence, with spaces and punctuation in it. The benefit of a passphrase is that typically they’re easier to remember, but more difficult to crack due to their length. For every additional character in the length of a password or passphrase, the time it would take to break increases exponentially. Ultimately that means that having a long password or passphrase can make you far more secure than having a short one with some symbols or numbers in it. 

Chủ Đề