Skip to main content
Improvements
Source Link
Dharman
  • 33.9k
  • 27
  • 106
  • 157

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_passwordhashed password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

added 3 characters in body
Source Link
Dharman
  • 33.9k
  • 27
  • 106
  • 157

Using password_hash is the recommended way to store passwords. Don't separateseparate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer)ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

added 35 characters in body
Source Link
Dharman
  • 33.9k
  • 27
  • 106
  • 157

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value. When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

Using password_hash is the recommended way to store passwords. Don't separate them to DB and files.

Let's say we have the following input:

$password = $_POST['password']; 

I don't validate the input just for the sake of understanding the concept.

You first hash the password by doing this:

$hashed_password = password_hash($password, PASSWORD_DEFAULT); 

Then see the output:

var_dump($hashed_password); 

As you can see it's hashed. (I assume you did those steps).

Now you store this hashed_password in your database, ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer). When a user asks to log them in, you check the password input with this hash value in the database, by doing this:

// Query the database for username and password // ... if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in. } // Else, Redirect them back to the login page. 

Official Reference

grammar and clarifications
Source Link
miken32
  • 42.5k
  • 16
  • 127
  • 177
Loading
Reference link added
Source Link
Roshana Pitigala
  • 8.9k
  • 9
  • 53
  • 87
Loading
added 2 characters in body
Source Link
Akar
  • 5.4k
  • 3
  • 27
  • 40
Loading
deleted 3 characters in body
Source Link
Akar
  • 5.4k
  • 3
  • 27
  • 40
Loading
Source Link
Akar
  • 5.4k
  • 3
  • 27
  • 40
Loading