How to add the password policy on user or employee form with the required,A number(0...9), especial character(@, *, ...), Password size > 6, A capital letter(A...Z), etc
Do you have any solution for to implement this policy.?
If you take a look at the user definition, you can find the password field:
'password': fields.char('Password', size=64, invisible=True, copy=False,
help="Keep empty if you don't want the user to be able to connect on the system."),
In order to implement your desired behavior, create an 'onchange' method for the password field like this:
@api.onchange('password')
def check_password(self):
where you perform the necessary verifications.
To see any results, you can create a new field called 'passwordOK', defaulted on true. If after the check the password is not ok, you can set it on false and this way you can control displaying an error message in the view.
To control the display of the message, you can try adding this to the view:
attrs="{'invisible': [('passwordOK', '=', True)]}"
EDIT: I'll show you how I did it in the view. This may not be the best solution but works just fine.
Instead of a boolean variable, I used a message string, like this:
'message': fields.text('Message'),
This variable will contain your warning message (Example:"Password must be alphanumeric"). You give value to this attribute when verifying the password security, in the method decorated with @api.onchange. In order to display the message, the field should look like this:
<field name="message" readonly="True" style="color:red" attrs="{'invisible': [('message', '=', '')]}"/>
As you can see, it will be displayed only when it's non-empty (Also it will be colored in red). Odoo will automatically update the field value when you modify it in your onchange method.