Can i customize p:password strength?

UI Components for JSF
nasir
Posts: 11
Joined: 26 Mar 2013, 09:09

08 Oct 2013, 13:55

Hi,
I would like to know if i could customize the strength calculation process for p:password component. It would be great if there could be an attribute to this component which takes a regular expression and judges the strength based on that.
Or even more, have 3 attributes which take regular expression, one for each strength level (e.g. weakRegex, goodRegex, strongRegex).

Thanks

rubus
Posts: 517
Joined: 01 Oct 2010, 09:41
Location: Belgium

08 Oct 2013, 14:35

Hello,

The algorithm is embedded in the Primefaces javascript code. And thus can't be changed.

If needed, create a request to allow a new attribute that defines the name of a js function that needs to calculate the strength.

regards
Rudy
PrimeFaces version 3.5, Tomcat 7, Mojarra 2.1.13
PrimeFaces version 4.0, Glassfish 4.0
PrimeFaces version 5.0, WLS 12.1.2
If you haven't read the forum rules read them now : viewtopic.php?f=3&t=1194

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

08 Oct 2013, 14:40

Alternative way is to override;

Code: Select all

PrimeFaces.widget.Password.prototype.testStrength= function(str) {
        //return a number between 0 and 100.
    }
Add your script at the pages where you have password components.

Ranges for levels;

0, 30 : Weak
30, 80 : Medium
80,100 : Strong

This turned out to be nice example of how to override PrimeFaces JS APIs :)

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

08 Oct 2013, 15:07

Really very good example for overriding the Primefaces js APIs.If it is a bug fix/big change in JS code then I will prefer overriding enter JS file instead few code snippets.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

rubus
Posts: 517
Joined: 01 Oct 2010, 09:41
Location: Belgium

08 Oct 2013, 16:20

Optimus,

Indeed good example. I though the prototype method would be overwritten by the actual method.

Learning something new, have to test such a strategy.

regards
Rudy
PrimeFaces version 3.5, Tomcat 7, Mojarra 2.1.13
PrimeFaces version 4.0, Glassfish 4.0
PrimeFaces version 5.0, WLS 12.1.2
If you haven't read the forum rules read them now : viewtopic.php?f=3&t=1194

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

08 Oct 2013, 17:07

In the past I overwritten 50% of PrimeFaces, but now 0% :-). Everything works more or less as expected. Regarding password strength - there is no customization options. But to write an own logic is quite simple with pure JavaScript and Reg Ex. There are 1000 examples in the web. I had to do this last week for an old application, can post later if somebody needs. Customization in JavaScript is not good, by the way. We had to write the script flexible and only customize input parameters coming from Java. So, the idea is to write the logic in the JS script once and customize it via parameters such as min. allowed count of input characters, groups of characters (digits, low, upper cases, special characters). Parameters are included in Reg Ex. At the end, there are two-three Reg Ex. to be customized for a week, medium, strong password.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

08 Oct 2013, 17:48

Oleg wrote:In the past I overwritten 50% of PrimeFaces, but now 0% :-). Everything works more or less as expected. Regarding password strength - there is no customization options. But to write an own logic is quite simple with pure JavaScript and Reg Ex. There are 1000 examples in the web. I had to do this last week for an old application, can post later if somebody needs. Customization in JavaScript is not good, by the way. We had to write the script flexible and only customize input parameters coming from Java. So, the idea is to write the logic in the JS script once and customize it via parameters such as min. allowed count of input characters, groups of characters (digits, low, upper cases, special characters). Parameters are included in Reg Ex. At the end, there are two-three Reg Ex. to be customized for a week, medium, strong password.
Interesting.But i feel writing the script logic which contain lots of RegEx may not be easy for major changes,it might be useful&easy for group of characters,min&max changes etc.If you already done for any component or sample use case will give a good idea on this.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

nasir
Posts: 11
Joined: 26 Mar 2013, 09:09

08 Oct 2013, 21:36

Thank you all (specially Optimus) for your time and support. Primefaces Rocks!

blackrose
Posts: 2
Joined: 09 Oct 2013, 10:40

09 Oct 2013, 12:10

The algorithm is embedded in the Primefaces javascript code. And thus can't be changed.

If needed, create a request to allow a new attribute that defines the name of a js function that needs to calculate the strength.
GuL

blackrose
Posts: 2
Joined: 09 Oct 2013, 10:40

09 Oct 2013, 12:11

i like this forum.... thanks and keep it up
GuL

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 64 guests