$password = "MySecurePassword123"; $hashedPassword = hashPassword($password, PASSWORD_DEFAULT); // Store hashedPassword in database
$password = "MySecurePassword123"; $hashedPassword = hashPassword($password, PASSWORD_BCRYPT, ['cost' => 12]); // Authenticate user by comparing hashedPassword with stored hashIn this example, the password "MySecurePassword123" is hashed using the bcrypt hash algorithm with a cost factor of 12. The resulting hashed password can then be used for authentication purposes by comparing it with the stored hash. The hashPassword function is part of the PHP password hashing API, which is included in the default installation of PHP since version 5.5.0.