'phpass:$pass_hash' /* Password encrypted by YOURLS */,"; // Add the user on a new line after the start of the passwords array $new_contents = preg_replace('/(yourls_user_passwords\s=\sarray\()/', '$0 ' . PHP_EOL . $user_line, $configdata, -1, $count); if ($count === 0) { die('Couldn\'t add user, plugin may not be compatible with YourLS version'); } else if ($count > 1) { die('Added user more than once. Check config file.'); } $success = file_put_contents( YOURLS_CONFIGFILE, $new_contents ); if ( $success === false ) { die('Unable to save config file'); } return $pass_hash; } /** * Hashes password the same way as yourls_hash_passwords_now() **/ function ldapauth_hash_password ($password) { $pass_hash = yourls_phpass_hash( $password ); // PHP would interpret $ as a variable, so replace it in storage. $pass_hash = str_replace( '$', '!', $pass_hash ); return $pass_hash; }