diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/auth_password_policy/models/res_users.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/auth_password_policy/models/res_users.py')
| -rw-r--r-- | addons/auth_password_policy/models/res_users.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/addons/auth_password_policy/models/res_users.py b/addons/auth_password_policy/models/res_users.py new file mode 100644 index 00000000..b938acd5 --- /dev/null +++ b/addons/auth_password_policy/models/res_users.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from odoo import api, models, _ +from odoo.exceptions import UserError + + +class ResUsers(models.Model): + _inherit = 'res.users' + + @api.model + def get_password_policy(self): + params = self.env['ir.config_parameter'].sudo() + return { + 'minlength': int(params.get_param('auth_password_policy.minlength', default=0)), + } + + def _set_password(self): + self._check_password_policy(self.mapped('password')) + + super(ResUsers, self)._set_password() + + def _check_password_policy(self, passwords): + failures = [] + params = self.env['ir.config_parameter'].sudo() + + minlength = int(params.get_param('auth_password_policy.minlength', default=0)) + for password in passwords: + if not password: + continue + if len(password) < minlength: + failures.append(_(u"Passwords must have at least %d characters, got %d.") % (minlength, len(password))) + + if failures: + raise UserError(u'\n\n '.join(failures)) |
