encrypt a password using sha1 in php

To encrypt a password using SHA1 in PHP, you can use the sha1() function. Here's an example:

main.php
$password = "password123";
$encrypted_password = sha1($password);

echo "Original password: " . $password . "<br>";
echo "Encrypted password: " . $encrypted_password;
167 chars
6 lines

In this example, the original password is "password123". The sha1() function takes the password as input and returns the SHA1 hash of the password. The resulting hash is assigned to the variable $encrypted_password.

The output of the program would be:

main.php
Original password: password123
Encrypted password: cbfdac6008f9cab4083784cbd1874f76618d2a97
92 chars
3 lines

Note that SHA1 is not considered a secure cryptographic algorithm for password storage, and it is recommended to use stronger algorithms such as bcrypt or Argon2 instead.

gistlibby LogSnag