* Copyright 1999-2001, VA Linux Systems, Inc.
* Copyright 2009-2011, Roland Mas
* Copyright 2009-2011, Franck Villaume - Capgemini
- * Copyright (c) 2010, 2011, 2012
- * Thorsten Glaser <t.glaser@tarent.de>
+ * Copyright 2010-2012, Thorsten Glaser - Tarent
* Copyright 2010-2012, Alain Peyrat - Alcatel-Lucent
- * Copyright 2013,2016-2017, Franck Villaume - TrivialDev
+ * Copyright 2013,2016-2018, Franck Villaume - TrivialDev
* Copyright 2016, Stéphane-Eymeric Bredthauer - TrivalDev
*
* This file is part of FusionForge. FusionForge is free software;
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/**
- * htpasswd_apr1_md5 - generate htpasswd md5 format password
- *
- * @param string $plainpasswd the plain string password
- * @return string the apr1 string passwords
- *
- * From http://www.php.net/manual/en/function.crypt.php#73619
- */
-function htpasswd_apr1_md5($plainpasswd) {
- $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
- $len = strlen($plainpasswd);
- $text = $plainpasswd.'$apr1$'.$salt;
- $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd));
- $tmp = '';
- for ($i = $len; $i > 0; $i -= 16) {
- $text .= substr($bin, 0, min(16, $i));
- }
- for ($i = $len; $i > 0; $i >>= 1) {
- $text .= ($i & 1)? chr(0) : $plainpasswd{0};
- }
- $bin = pack("H32", md5($text));
- for ($i = 0; $i < 1000; $i++) {
- $new = ($i & 1)? $plainpasswd : $bin;
- if ($i % 3) {
- $new .= $salt;
- }
- if ($i % 7) {
- $new .= $plainpasswd;
- }
- $new .= ($i & 1)? $bin : $plainpasswd;
- $bin = pack("H32", md5($new));
- }
- for ($i = 0; $i < 5; $i++) {
- $k = $i + 6;
- $j = $i + 12;
- if ($j == 16) {
- $j = 5;
- }
- $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
- }
- $tmp = chr(0).chr(0).$bin[11].$tmp;
- $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
- "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
- return "$"."apr1"."$".$salt."$".$tmp;
-}
-
/**
* is_utf8 - utf-8 detection
*