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

Commit e75661c

Browse files
committed
Move decypher function in AJXP_Utils instead of AbstractAjxpUser.
Do not override __AJXP_VALUE_SET__ when parsing standard form. New parameter $complexChars in generateRandomString function.
1 parent 6a1c267 commit e75661c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

core/src/core/classes/class.AJXP_Safe.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ public function store()
110110
{
111111
$_SESSION["AJXP_SAFE_CREDENTIALS"] = base64_encode($this->user.$this->separator.$this->encodedPassword);
112112
}
113+
113114
/**
114115
* Load the credentials from session
115-
* @return
116+
* @param string $encodedString
117+
* @return void
116118
*/
117119
public function load($encodedString = "")
118120
{
@@ -235,7 +237,7 @@ public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
235237
$wallet = $loggedUser->getPref("AJXP_WALLET");
236238
if (is_array($wallet) && isSet($wallet[$repository->getId()][$optionsPrefix."USER"])) {
237239
$user = $wallet[$repository->getId()][$optionsPrefix."USER"];
238-
$password = $loggedUser->decodeUserPassword($wallet[$repository->getId()][$optionsPrefix."PASS"]);
240+
$password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $wallet[$repository->getId()][$optionsPrefix."PASS"]);
239241
}
240242
}
241243
}
@@ -247,7 +249,7 @@ public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
247249
$p = $loggedUser->mergedRole->filterParameterValue("access.".$repository->getAccessType(), $optionsPrefix."PASS", $repository->getId(), "");
248250
if (!empty($u) && !empty($p)) {
249251
$user = $u;
250-
$password = $loggedUser->decodeUserPassword($p);
252+
$password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $p);
251253
}
252254
}
253255
}

core/src/core/classes/class.AJXP_Utils.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,15 @@ public static function getRemoteContent($url)
16281628
}
16291629
}
16301630

1631-
public static function parseStandardFormParameters(&$repDef, &$options, $userId = null, $prefix = "DRIVER_OPTION_", $binariesContext = null)
1631+
public static function decypherStandardFormPassword($userId, $password){
1632+
if (function_exists('mcrypt_decrypt')) {
1633+
// We have encoded as base64 so if we need to store the result in a database, it can be stored in text column
1634+
$password = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), base64_decode($password), MCRYPT_MODE_ECB), "\0");
1635+
}
1636+
return $password;
1637+
}
1638+
1639+
public static function parseStandardFormParameters(&$repDef, &$options, $userId = null, $prefix = "DRIVER_OPTION_", $binariesContext = null, $cypheredPassPrefix = "")
16321640
{
16331641
if ($binariesContext === null) {
16341642
$binariesContext = array("USER" => (AuthService::getLoggedUser()!= null)?AuthService::getLoggedUser()->getId():"shared");
@@ -1650,9 +1658,9 @@ public static function parseStandardFormParameters(&$repDef, &$options, $userId
16501658
} else if ($type == "array") {
16511659
$value = explode(",", $value);
16521660
} else if ($type == "password" && $userId!=null) {
1653-
if (trim($value) != "" && function_exists('mcrypt_encrypt')) {
1661+
if (trim($value) != "" && $value != "__AJXP_VALUE_SET__" && function_exists('mcrypt_encrypt')) {
16541662
// We encode as base64 so if we need to store the result in a database, it can be stored in text column
1655-
$value = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), $value, MCRYPT_MODE_ECB));
1663+
$value = $cypheredPassPrefix . base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), $value, MCRYPT_MODE_ECB));
16561664
}
16571665
} else if ($type == "binary" && $binariesContext !== null) {
16581666
if (!empty($value)) {
@@ -1929,11 +1937,12 @@ public static function pbkdf2_create_hash($password)
19291937
/**
19301938
* generates a random password, uses base64: 0-9a-zA-Z
19311939
* @param int [optional] $length length of password, default 24 (144 Bit)
1940+
* @param bool $complexChars
19321941
* @return string password
19331942
*/
1934-
public static function generateRandomString($length = 24)
1943+
public static function generateRandomString($length = 24, $complexChars = false)
19351944
{
1936-
if (function_exists('openssl_random_pseudo_bytes') && USE_OPENSSL_RANDOM) {
1945+
if (function_exists('openssl_random_pseudo_bytes') && USE_OPENSSL_RANDOM && !$complexChars) {
19371946
$password = base64_encode(openssl_random_pseudo_bytes($length, $strong));
19381947
if($strong == TRUE)
19391948
return substr(str_replace(array("/","+"), "", $password), 0, $length); //base64 is about 33% longer, so we need to truncate the result
@@ -1942,6 +1951,9 @@ public static function generateRandomString($length = 24)
19421951
//fallback to mt_rand if php < 5.3 or no openssl available
19431952
$characters = '0123456789';
19441953
$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
1954+
if($complexChars){
1955+
$characters .= "!@#$%&*?";
1956+
}
19451957
$charactersLength = strlen($characters)-1;
19461958
$password = '';
19471959

0 commit comments

Comments
 (0)