summaryrefslogtreecommitdiffstats
path: root/apps/sharebymail/lib
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-04-19 16:56:34 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2017-04-20 16:33:26 +0200
commit972b4c04e2ea3bf96533c111853a57177231c638 (patch)
treee4b17437ede942eaff7fb0fc195d92e1e58cccb8 /apps/sharebymail/lib
parent428d7cdb5e7be1d5ede6d5084459660b22c84b2c (diff)
downloadnextcloud-server-972b4c04e2ea3bf96533c111853a57177231c638.tar.gz
nextcloud-server-972b4c04e2ea3bf96533c111853a57177231c638.zip
respect password policy for auto generated passwords
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/sharebymail/lib')
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php35
1 files changed, 32 insertions, 3 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php
index 5307a8cb223..f31a774b1d1 100644
--- a/apps/sharebymail/lib/ShareByMailProvider.php
+++ b/apps/sharebymail/lib/ShareByMailProvider.php
@@ -21,6 +21,7 @@
namespace OCA\ShareByMail;
+use OC\CapabilitiesManager;
use OC\HintException;
use OC\Share20\Exception\InvalidShare;
use OCA\ShareByMail\Settings\SettingsManager;
@@ -43,7 +44,6 @@ use OC\Share20\Share;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
-use OCP\Template;
/**
* Class ShareByMail
@@ -88,6 +88,9 @@ class ShareByMailProvider implements IShareProvider {
/** @var IHasher */
private $hasher;
+ /** @var CapabilitiesManager */
+ private $capabilitiesManager;
+
/**
* Return the identifier of this provider.
*
@@ -112,6 +115,7 @@ class ShareByMailProvider implements IShareProvider {
* @param SettingsManager $settingsManager
* @param Defaults $defaults
* @param IHasher $hasher
+ * @param CapabilitiesManager $capabilitiesManager
*/
public function __construct(
IDBConnection $connection,
@@ -125,7 +129,8 @@ class ShareByMailProvider implements IShareProvider {
IManager $activityManager,
SettingsManager $settingsManager,
Defaults $defaults,
- IHasher $hasher
+ IHasher $hasher,
+ CapabilitiesManager $capabilitiesManager
) {
$this->dbConnection = $connection;
$this->secureRandom = $secureRandom;
@@ -139,6 +144,7 @@ class ShareByMailProvider implements IShareProvider {
$this->settingsManager = $settingsManager;
$this->defaults = $defaults;
$this->hasher = $hasher;
+ $this->capabilitiesManager = $capabilitiesManager;
}
/**
@@ -202,13 +208,36 @@ class ShareByMailProvider implements IShareProvider {
);
}
- $password = $this->generateToken(8);
+ $passwordPolicy = $this->getPasswordPolicy();
+ $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS;
+ $passwordLength = 8;
+ if (!empty($passwordPolicy)) {
+ $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength;
+ $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : '';
+ }
+
+ $password = $this->secureRandom->generate($passwordLength, $passwordCharset);
+
$share->setPassword($this->hasher->hash($password));
return $password;
}
/**
+ * get password policy
+ *
+ * @return array
+ */
+ protected function getPasswordPolicy() {
+ $capabilities = $this->capabilitiesManager->getCapabilities();
+ if (isset($capabilities['password_policy'])) {
+ return $capabilities['password_policy'];
+ }
+
+ return [];
+ }
+
+ /**
* create activity if a file/folder was shared by mail
*
* @param IShare $share