Skip to content

Conversation

@dgrammlich
Copy link

Hi!

We implemented the expiration time for passwords for a customer and wanted to show you the solution. Maybe you can give us feedback on our code and / or merge it if you like it.

We are excited to hear from you!

Cheers
Alexander and Daniela

@tflidd
Copy link

tflidd commented Dec 29, 2017

@LukasReschke @nickvergessen @MorrisJobke any reason we never gave any feedback to this pull request?

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why no one reacted. But I'm not subscribed to this repository so I didn't receive a notification for it.

*/
public function deleteUserExpirationData($userUid) {
$sql = 'DELETE FROM oc_password_policy_expiration';
$sql .= ' WHERE uid="' . $userUid . '"';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a SQL injection.
Must use a parameter at least.

Best would be to use $this->db->getQueryBuilder() instead.

Same applies to all other queries.

@@ -0,0 +1,43 @@
<?php
namespace OCA\Password_Policy\Hook;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing header with Licence etc.
Same for all other files.

$sql = "INSERT INTO oc_password_policy_expiration";
$sql .= " (" . implode(',', array_keys($fields)) . ")";
$sql .= ' VALUES ("' . implode('","', $fields) .'")';
$sql .= " ON DUPLICATE KEY UPDATE ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work on all supported databases.

Either use $this->db->insertIfNotExist() and depending on the result do the update or manually select before the update/insert

}

public function findAllUsers() {
$sql = 'SELECT * FROM oc_users LEFT JOIN oc_password_policy_expiration ON oc_users.uid = oc_password_policy_expiration.uid';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columns need to be escaped with ` or you use the query builder which does it automatically.

$message = $this->mailer->createMessage();
$message->setFrom([$from => $this->defaults->getName()]);
$message->setTo([$userEmail => $userId]);
$message->setSubject($subject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime setTemplate was added, which comes with nice and easy HTML emails.
Maybe you could also have a look at this.

$this->setInterval(24 * 60 * 60);

$this->config = $config;
$this->logger = \OC::$server->getLogger();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inject it instead.

$this->groupManager = $groupManager;

$connection = \OC::$server->getDatabaseConnection();
$this->userDAO = new UserDAO($connection);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this.

@wiswedel
Copy link

wiswedel commented May 6, 2019

ping @dgrammlich

@nickvergessen
Copy link
Member

Well sionce this is almost two years old, I guess it needs some more changes.

Additionally to the above list, emails should use the email template system and database.xml is not recommended anymore.

@dgrammlich
Copy link
Author

Hi, thanks for your review, @nickvergessen, and sorry for the late feedback. Due to a longer illness at the time of your review I couldn't respond and then just lost track of this issue.

Nevertheless I'm no longer a member of the project and the company. Maybe @alex-boehm can tell more, or you can just close this MR due to obsolete code.

@jotoeri
Copy link
Member

jotoeri commented Mar 16, 2021

/me just pushing the button here. 🙈
Should also be implemented meanwhile in #101

@jotoeri jotoeri closed this Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants