简体   繁体   English

jQuery 密码强度检查器

[英]jQuery password strength checker

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对 jQuery 很陌生,我编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是每次用户输入一个字符时,都会评估内容以测试他们输入的密码的强度......我相信每个人之前都见过这些。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以值 1 开头。使用小写字符时,分数增加到 2。使用数字时,分数再次增加 1,与大写时相同当密码长度为 5 个或更多字符时使用字符。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.返回的是每次按下键时密码的强度,即从 1 到 5 的值。

So, about my question.那么,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成它的方式似乎不像 jQuery 那样......几乎就像我刚刚完成了直接的 javascript 一样。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我有没有做过什么或忽略了什么? Any suggestions from smarter people than myself?比我更聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.我对jQuery很陌生,并且编写了一个简单的函数来检查每个按键的密码强度。

The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.这个想法是,每次用户输入一个字符时,都会对内容进行评估,以测试他们输入的密码的强度……我敢肯定,每个人以前都看过这些密码。

Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.无论如何,我使用的逻辑是没有密码以1开头。使用小写字符时,分数增加到2。使用数字时,分数再次增加1,与大写相同使用字符,并且密码长度为5个或更多字符时。

What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.每次按键时返回的密码强度为1到5。

So, about my question.所以,关于我的问题。 The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript.我完成的方式似乎不像jQuery,...好像我也可以直接编写javascript。 Also I was wondering about my logic.我也想知道我的逻辑。 Have I done anything done or overlooked something?我做过什么事还是忽略了什么? Any suggestions from smarter people than myself?比我聪明的人有什么建议吗?

Any suggestions or advice would be appreciated.任何建议或意见将不胜感激。

$(document).ready(function(){

        $("#pass_strength").keyup(function() {

            var strength = 1;

            /*length 5 characters or more*/
            if(this.value.length >= 5) {
                strength++;
            }

            /*contains lowercase characters*/
            if(this.value.match(/[a-z]+/)) {
                strength++;
            }

            /*contains digits*/
            if(this.value.match(/[0-9]+/)) {
                strength++;
            }

            /*contains uppercase characters*/
            if(this.value.match(/[A-Z]+/)) {
                strength++;
            }

            alert(strength);
        });
     });

implementation for scoring based on variation, mess and length:基于变化、混乱和长度进行评分的实现:

function scorePass(pass) {  
    let score = 0;
    
    // variation range
    score += new Set(pass.split("")).size * 1;
    const charCodes = [...new Set(pass.split(''))].map(x=>x.toLowerCase().charCodeAt(0));

    // shuffle score - bonus for messing things up
    for (let i=1; i < charCodes.length;i++)
    {
        const dist = Math.abs(charCodes[i-1]-charCodes[i]);
        if (dist>60)
            score += 15;
        else if (dist>8)
            score += 10;
        else if (dist>1)
            score += 2;
    }
    
    // bonus for length
    score += (pass.length - 6) * 3;

    return parseInt(score);
}

abcעfדg94a > jefPYM583^ > abcABC!@#$ abcעfדg94a > jefPYM583^ > abcABC!@#$

https://codepen.io/oriadam/pen/ExmaoYy https://codepen.io/oriadam/pen/ExmaoYy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM