Advertisement
ivana_andreevska

Password Strength and Progress Bar

Dec 9th, 2021 (edited)
4,473
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.42 KB | None | 1 0
  1. //HTML
  2.  
  3. <input type="text" id="autocomplete" placeholder="Enter product name here">
  4.  
  5. <div>
  6.     <input type="password" id="pass">
  7.     <div id="progress">
  8.  
  9.     </div>
  10. </div>
  11.  
  12.  
  13.  
  14. //JQUERY
  15.  
  16.     $("#pass").keydown( function (){
  17.         var strength=check_strength($("#pass").val())
  18.  
  19.         if(strength==1){
  20.             $("#progress").progressbar({
  21.                 value:33
  22.             })
  23.             $("#progress").find(".ui-progressbar-value").css({
  24.                 background:"red"
  25.             })
  26.         }
  27.         if(strength==2)
  28.         {
  29.             $("#progress").progressbar({
  30.                 value:66
  31.             })
  32.             $("#progress").find(".ui-progressbar-value").css({
  33.                 background:"yellow"
  34.             })
  35.         }
  36.         if(strength==3)
  37.         {
  38.             $("#progress").progressbar({
  39.                 value:100
  40.             })
  41.             $("#progress").find(".ui-progressbar-value").css({
  42.                 background:"green"
  43.             })
  44.         }
  45.     })
  46.  
  47.     function check_strength(pass)
  48.     {
  49.         var result=0
  50.  
  51.         result+=/[a=zA-Z]+/.test(pass)?1:0;
  52.         result+=/[0-9]+/.test(pass)?1:0;
  53.         var special_sign="!@#$%^&*() :"
  54.         for(var i=0;i<special_sign.length;i++)
  55.         {
  56.             if(pass.indexOf(special_sign[i]>-1)){
  57.                 result+=1;
  58.                 break;
  59.             }
  60.         }
  61.         return result;
  62.     }
  63. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement