Textpattern | PHP Cross Reference | Content Management Systems |
Description: Adapter for PHPass.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Adapter for PHPass. 26 * 27 * @since 4.6.0 28 * @package Password 29 */ 30 31 namespace Textpattern\Password\Adapter; 32 33 class PasswordHash implements \Textpattern\Password\AdapterInterface 34 { 35 /** 36 * Stores an instance of PHPass. 37 * 38 * @var \PasswordHash 39 */ 40 41 private $phpass; 42 private $native; 43 44 /** 45 * Constructor. 46 */ 47 48 public function __construct() 49 { 50 $this->phpass = new \PasswordHash(PASSWORD_COMPLEXITY, PASSWORD_PORTABILITY); 51 $this->native = function_exists('password_hash'); 52 } 53 54 /** 55 * {@inheritdoc} 56 */ 57 58 public function verify($password, $hash) 59 { 60 return $this->native && password_verify($password, $hash) ? 1 : $this->phpass->CheckPassword($password, $hash); 61 } 62 63 /** 64 * {@inheritdoc} 65 */ 66 67 public function hash($password) 68 { 69 return $this->native ? password_hash($password, PASSWORD_DEFAULT) : $this->phpass->HashPassword($password); 70 } 71 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title