• <legend id='g4m2c'><style id='g4m2c'><dir id='g4m2c'><q id='g4m2c'></q></dir></style></legend>

      <small id='g4m2c'></small><noframes id='g4m2c'>

      1. <tfoot id='g4m2c'></tfoot>

          <bdo id='g4m2c'></bdo><ul id='g4m2c'></ul>

      2. <i id='g4m2c'><tr id='g4m2c'><dt id='g4m2c'><q id='g4m2c'><span id='g4m2c'><b id='g4m2c'><form id='g4m2c'><ins id='g4m2c'></ins><ul id='g4m2c'></ul><sub id='g4m2c'></sub></form><legend id='g4m2c'></legend><bdo id='g4m2c'><pre id='g4m2c'><center id='g4m2c'></center></pre></bdo></b><th id='g4m2c'></th></span></q></dt></tr></i><div id='g4m2c'><tfoot id='g4m2c'></tfoot><dl id='g4m2c'><fieldset id='g4m2c'></fieldset></dl></div>

        如何在 Python 中测试正则表达式密码?

        时间:2023-09-28
          <legend id='ciJLr'><style id='ciJLr'><dir id='ciJLr'><q id='ciJLr'></q></dir></style></legend>
        • <i id='ciJLr'><tr id='ciJLr'><dt id='ciJLr'><q id='ciJLr'><span id='ciJLr'><b id='ciJLr'><form id='ciJLr'><ins id='ciJLr'></ins><ul id='ciJLr'></ul><sub id='ciJLr'></sub></form><legend id='ciJLr'></legend><bdo id='ciJLr'><pre id='ciJLr'><center id='ciJLr'></center></pre></bdo></b><th id='ciJLr'></th></span></q></dt></tr></i><div id='ciJLr'><tfoot id='ciJLr'></tfoot><dl id='ciJLr'><fieldset id='ciJLr'></fieldset></dl></div>

              <tbody id='ciJLr'></tbody>
            <tfoot id='ciJLr'></tfoot>

            <small id='ciJLr'></small><noframes id='ciJLr'>

                <bdo id='ciJLr'></bdo><ul id='ciJLr'></ul>
                1. 本文介绍了如何在 Python 中测试正则表达式密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Python 中使用正则表达式,我如何验证用户的密码是:

                  Using a regex in Python, how can I verify that a user's password is:

                  • 至少 8 个字符
                  • 必须限于,但不具体要求:
                    • 大写字母:A-Z
                    • 小写字母:a-z
                    • 数字:0-9
                    • 任何特殊字符:@#$%^&+=

                    注意,所有字母/数字/特殊字符都是可选的.我只想验证密码长度是否至少为 8 个字符,并且仅限于字母/数字/特殊字符.如果他们愿意,用户可以选择更强/更弱的密码.到目前为止,我所拥有的是:

                    Note, all the letter/number/special chars are optional. I only want to verify that the password is at least 8 chars in length and is restricted to a letter/number/special char. It's up to the user to pick a stronger / weaker password if they so choose. So far what I have is:

                    import re
                    pattern = "^.*(?=.{8,})(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$"
                    password = raw_input("Enter string to test: ")
                    result = re.findall(pattern, password)
                    if (result):
                        print "Valid password"
                    else:
                        print "Password not valid"
                    

                    推荐答案

                    import re
                    password = raw_input("Enter string to test: ")
                    if re.fullmatch(r'[A-Za-z0-9@#$%^&+=]{8,}', password):
                        # match
                    else:
                        # no match
                    

                    {8,} 表示至少 8 个"..fullmatch 函数要求整个字符串匹配整个正则表达式,而不仅仅是一部分.

                    The {8,} means "at least 8". The .fullmatch function requires the entire string to match the entire regex, not just a portion.

                    这篇关于如何在 Python 中测试正则表达式密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在我自己的模板中使用内置的密码重置/更改视图 下一篇:Python 从数据库中存储和检索密码的最安全方法

                  相关文章

                2. <small id='i7qp5'></small><noframes id='i7qp5'>

                3. <i id='i7qp5'><tr id='i7qp5'><dt id='i7qp5'><q id='i7qp5'><span id='i7qp5'><b id='i7qp5'><form id='i7qp5'><ins id='i7qp5'></ins><ul id='i7qp5'></ul><sub id='i7qp5'></sub></form><legend id='i7qp5'></legend><bdo id='i7qp5'><pre id='i7qp5'><center id='i7qp5'></center></pre></bdo></b><th id='i7qp5'></th></span></q></dt></tr></i><div id='i7qp5'><tfoot id='i7qp5'></tfoot><dl id='i7qp5'><fieldset id='i7qp5'></fieldset></dl></div>

                  <tfoot id='i7qp5'></tfoot><legend id='i7qp5'><style id='i7qp5'><dir id='i7qp5'><q id='i7qp5'></q></dir></style></legend>
                  • <bdo id='i7qp5'></bdo><ul id='i7qp5'></ul>