Password check with combined regexes [duplicate]












3
















This question already has an answer here:




  • Regex no two consecutive characters are the same

    2 answers




In Laravel, I have to do a strong security check for passwords.
I don't have any prior knowledge of Regex, but I think it is the best solution in my case and I believe it can do what I need. So here are my client's rules:



A password must contain all 4 characters’ types:




  • Lowercase : a-z

  • Uppercase : A-Z

  • Numeric : 0-9

  • Special characters: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~

  • Your user name, first name or last name should not be part of your password.

  • Consecutive set of the same character should never be used (aaaaaa..., 1111111...)


Searching through Stackoverflow, I found a similar solution which deals with first 4 rules, but with my necessary modifications:



/^.*(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/


Also, I found a solution for the last rule (consecutive set of characters - 6 in this case), which should probably be a little bit more modified, because I actually don't want a password to have a repeating set of characters. It searches for repeating set:



/(.)1{5,}/


About the "names can't be part of the password" rule, is it even possible to do it within regex, since we have to pass a string parameter(s) to it?



Anyway, I would like to have 1 regex for all rules combined. Since that probably isn't doable, is it possible to have at least a combined regex for everything except the part about "no usernames allowed"? And then I could do a custom validation for that specific rule.



I don't think that my question is duplicate, since it's a combination of at least 2 questions together. Given "duplicate" is just a part of my regex, which I didn't know how to combine with the other one.










share|improve this question















marked as duplicate by Wiktor Stribiżew regex
Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 10:31


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    3
















    This question already has an answer here:




    • Regex no two consecutive characters are the same

      2 answers




    In Laravel, I have to do a strong security check for passwords.
    I don't have any prior knowledge of Regex, but I think it is the best solution in my case and I believe it can do what I need. So here are my client's rules:



    A password must contain all 4 characters’ types:




    • Lowercase : a-z

    • Uppercase : A-Z

    • Numeric : 0-9

    • Special characters: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~

    • Your user name, first name or last name should not be part of your password.

    • Consecutive set of the same character should never be used (aaaaaa..., 1111111...)


    Searching through Stackoverflow, I found a similar solution which deals with first 4 rules, but with my necessary modifications:



    /^.*(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/


    Also, I found a solution for the last rule (consecutive set of characters - 6 in this case), which should probably be a little bit more modified, because I actually don't want a password to have a repeating set of characters. It searches for repeating set:



    /(.)1{5,}/


    About the "names can't be part of the password" rule, is it even possible to do it within regex, since we have to pass a string parameter(s) to it?



    Anyway, I would like to have 1 regex for all rules combined. Since that probably isn't doable, is it possible to have at least a combined regex for everything except the part about "no usernames allowed"? And then I could do a custom validation for that specific rule.



    I don't think that my question is duplicate, since it's a combination of at least 2 questions together. Given "duplicate" is just a part of my regex, which I didn't know how to combine with the other one.










    share|improve this question















    marked as duplicate by Wiktor Stribiżew regex
    Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 15 '18 at 10:31


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      3












      3








      3









      This question already has an answer here:




      • Regex no two consecutive characters are the same

        2 answers




      In Laravel, I have to do a strong security check for passwords.
      I don't have any prior knowledge of Regex, but I think it is the best solution in my case and I believe it can do what I need. So here are my client's rules:



      A password must contain all 4 characters’ types:




      • Lowercase : a-z

      • Uppercase : A-Z

      • Numeric : 0-9

      • Special characters: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~

      • Your user name, first name or last name should not be part of your password.

      • Consecutive set of the same character should never be used (aaaaaa..., 1111111...)


      Searching through Stackoverflow, I found a similar solution which deals with first 4 rules, but with my necessary modifications:



      /^.*(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/


      Also, I found a solution for the last rule (consecutive set of characters - 6 in this case), which should probably be a little bit more modified, because I actually don't want a password to have a repeating set of characters. It searches for repeating set:



      /(.)1{5,}/


      About the "names can't be part of the password" rule, is it even possible to do it within regex, since we have to pass a string parameter(s) to it?



      Anyway, I would like to have 1 regex for all rules combined. Since that probably isn't doable, is it possible to have at least a combined regex for everything except the part about "no usernames allowed"? And then I could do a custom validation for that specific rule.



      I don't think that my question is duplicate, since it's a combination of at least 2 questions together. Given "duplicate" is just a part of my regex, which I didn't know how to combine with the other one.










      share|improve this question

















      This question already has an answer here:




      • Regex no two consecutive characters are the same

        2 answers




      In Laravel, I have to do a strong security check for passwords.
      I don't have any prior knowledge of Regex, but I think it is the best solution in my case and I believe it can do what I need. So here are my client's rules:



      A password must contain all 4 characters’ types:




      • Lowercase : a-z

      • Uppercase : A-Z

      • Numeric : 0-9

      • Special characters: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~

      • Your user name, first name or last name should not be part of your password.

      • Consecutive set of the same character should never be used (aaaaaa..., 1111111...)


      Searching through Stackoverflow, I found a similar solution which deals with first 4 rules, but with my necessary modifications:



      /^.*(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/


      Also, I found a solution for the last rule (consecutive set of characters - 6 in this case), which should probably be a little bit more modified, because I actually don't want a password to have a repeating set of characters. It searches for repeating set:



      /(.)1{5,}/


      About the "names can't be part of the password" rule, is it even possible to do it within regex, since we have to pass a string parameter(s) to it?



      Anyway, I would like to have 1 regex for all rules combined. Since that probably isn't doable, is it possible to have at least a combined regex for everything except the part about "no usernames allowed"? And then I could do a custom validation for that specific rule.



      I don't think that my question is duplicate, since it's a combination of at least 2 questions together. Given "duplicate" is just a part of my regex, which I didn't know how to combine with the other one.





      This question already has an answer here:




      • Regex no two consecutive characters are the same

        2 answers








      regex laravel passwords






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 11:09







      Ivan Loler

















      asked Nov 15 '18 at 10:26









      Ivan LolerIvan Loler

      338




      338




      marked as duplicate by Wiktor Stribiżew regex
      Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 10:31


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Wiktor Stribiżew regex
      Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 10:31


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          2














          One option is to add a negative lookahead which asserts that nowhere in the entered password do two consecutive characters appear:



          /^(?!.*(.)1)(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/
          ^^^^^^^


          Note that the .* you had at the beginning of your pattern was probably misplaced. You don't need/want it there, because you want the lookaheads to fire before you begin matching the actual password.




          Demo






          share|improve this answer
























          • Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:40













          • Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:43




















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          One option is to add a negative lookahead which asserts that nowhere in the entered password do two consecutive characters appear:



          /^(?!.*(.)1)(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/
          ^^^^^^^


          Note that the .* you had at the beginning of your pattern was probably misplaced. You don't need/want it there, because you want the lookaheads to fire before you begin matching the actual password.




          Demo






          share|improve this answer
























          • Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:40













          • Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:43


















          2














          One option is to add a negative lookahead which asserts that nowhere in the entered password do two consecutive characters appear:



          /^(?!.*(.)1)(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/
          ^^^^^^^


          Note that the .* you had at the beginning of your pattern was probably misplaced. You don't need/want it there, because you want the lookaheads to fire before you begin matching the actual password.




          Demo






          share|improve this answer
























          • Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:40













          • Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:43
















          2












          2








          2







          One option is to add a negative lookahead which asserts that nowhere in the entered password do two consecutive characters appear:



          /^(?!.*(.)1)(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/
          ^^^^^^^


          Note that the .* you had at the beginning of your pattern was probably misplaced. You don't need/want it there, because you want the lookaheads to fire before you begin matching the actual password.




          Demo






          share|improve this answer













          One option is to add a negative lookahead which asserts that nowhere in the entered password do two consecutive characters appear:



          /^(?!.*(.)1)(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/
          ^^^^^^^


          Note that the .* you had at the beginning of your pattern was probably misplaced. You don't need/want it there, because you want the lookaheads to fire before you begin matching the actual password.




          Demo







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 10:27









          Tim BiegeleisenTim Biegeleisen

          230k1395147




          230k1395147













          • Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:40













          • Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:43





















          • Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:40













          • Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

            – Ivan Loler
            Nov 15 '18 at 10:43



















          Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

          – Ivan Loler
          Nov 15 '18 at 10:40







          Awesome! I only modified it a bit, because I think that I will have to specify how many repeating characters are allowed (in your example, "!Testt" is already not allowed), so it would be like this: /^(?!.*(.)1{5,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

          – Ivan Loler
          Nov 15 '18 at 10:40















          Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

          – Ivan Loler
          Nov 15 '18 at 10:43







          Accepted. And I also realised that my regex wasn't asking for both lower & uppercase, only 1 of them. So my final regex would be: /^(?!.*(.)1{5,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]).*$/

          – Ivan Loler
          Nov 15 '18 at 10:43







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine