Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Move decypher function in AJXP_Utils instead of AbstractAjxpUser.
Browse files Browse the repository at this point in the history
Do not override __AJXP_VALUE_SET__ when parsing standard form.
New parameter $complexChars in generateRandomString function.
  • Loading branch information
cdujeu committed Mar 27, 2015
1 parent 6a1c267 commit e75661c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 5 additions & 3 deletions core/src/core/classes/class.AJXP_Safe.php
Expand Up @@ -110,9 +110,11 @@ public function store()
{
$_SESSION["AJXP_SAFE_CREDENTIALS"] = base64_encode($this->user.$this->separator.$this->encodedPassword);
}

/**
* Load the credentials from session
* @return
* @param string $encodedString
* @return void
*/
public function load($encodedString = "")
{
Expand Down Expand Up @@ -235,7 +237,7 @@ public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
$wallet = $loggedUser->getPref("AJXP_WALLET");
if (is_array($wallet) && isSet($wallet[$repository->getId()][$optionsPrefix."USER"])) {
$user = $wallet[$repository->getId()][$optionsPrefix."USER"];
$password = $loggedUser->decodeUserPassword($wallet[$repository->getId()][$optionsPrefix."PASS"]);
$password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $wallet[$repository->getId()][$optionsPrefix."PASS"]);
}
}
}
Expand All @@ -247,7 +249,7 @@ public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
$p = $loggedUser->mergedRole->filterParameterValue("access.".$repository->getAccessType(), $optionsPrefix."PASS", $repository->getId(), "");
if (!empty($u) && !empty($p)) {
$user = $u;
$password = $loggedUser->decodeUserPassword($p);
$password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $p);
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -1628,7 +1628,15 @@ public static function getRemoteContent($url)
}
}

public static function parseStandardFormParameters(&$repDef, &$options, $userId = null, $prefix = "DRIVER_OPTION_", $binariesContext = null)
public static function decypherStandardFormPassword($userId, $password){
if (function_exists('mcrypt_decrypt')) {
// We have encoded as base64 so if we need to store the result in a database, it can be stored in text column
$password = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), base64_decode($password), MCRYPT_MODE_ECB), "\0");
}
return $password;
}

public static function parseStandardFormParameters(&$repDef, &$options, $userId = null, $prefix = "DRIVER_OPTION_", $binariesContext = null, $cypheredPassPrefix = "")
{
if ($binariesContext === null) {
$binariesContext = array("USER" => (AuthService::getLoggedUser()!= null)?AuthService::getLoggedUser()->getId():"shared");
Expand All @@ -1650,9 +1658,9 @@ public static function parseStandardFormParameters(&$repDef, &$options, $userId
} else if ($type == "array") {
$value = explode(",", $value);
} else if ($type == "password" && $userId!=null) {
if (trim($value) != "" && function_exists('mcrypt_encrypt')) {
if (trim($value) != "" && $value != "__AJXP_VALUE_SET__" && function_exists('mcrypt_encrypt')) {
// We encode as base64 so if we need to store the result in a database, it can be stored in text column
$value = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), $value, MCRYPT_MODE_ECB));
$value = $cypheredPassPrefix . base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), $value, MCRYPT_MODE_ECB));
}
} else if ($type == "binary" && $binariesContext !== null) {
if (!empty($value)) {
Expand Down Expand Up @@ -1929,11 +1937,12 @@ public static function pbkdf2_create_hash($password)
/**
* generates a random password, uses base64: 0-9a-zA-Z
* @param int [optional] $length length of password, default 24 (144 Bit)
* @param bool $complexChars
* @return string password
*/
public static function generateRandomString($length = 24)
public static function generateRandomString($length = 24, $complexChars = false)
{
if (function_exists('openssl_random_pseudo_bytes') && USE_OPENSSL_RANDOM) {
if (function_exists('openssl_random_pseudo_bytes') && USE_OPENSSL_RANDOM && !$complexChars) {
$password = base64_encode(openssl_random_pseudo_bytes($length, $strong));
if($strong == TRUE)
return substr(str_replace(array("/","+"), "", $password), 0, $length); //base64 is about 33% longer, so we need to truncate the result
Expand All @@ -1942,6 +1951,9 @@ public static function generateRandomString($length = 24)
//fallback to mt_rand if php < 5.3 or no openssl available
$characters = '0123456789';
$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if($complexChars){
$characters .= "!@#$%&*?";
}
$charactersLength = strlen($characters)-1;
$password = '';

Expand Down

0 comments on commit e75661c

Please sign in to comment.