Home Web Front-end JS Tutorial Two methods for JS to implement password levels that contain at least letters, uppercase and lowercase numbers, and characters_javascript skills

Two methods for JS to implement password levels that contain at least letters, uppercase and lowercase numbers, and characters_javascript skills

May 16, 2016 pm 04:16 PM
js Include Case letter character password number method grade

The examples in this article describe two methods of using JS to implement password levels that contain at least letters, uppercase and lowercase numbers, and characters. Share it with everyone for your reference. The details are as follows:

Foreword

Passwords can be easily broken if they are set too simply, so many websites set very strict requirements for passwords, usually 2 out of 3 letters, numbers, and characters, and are case-sensitive. If the password is set too simple, an error message will be given. Or display the password level (low, medium and high) to allow users to set advanced passwords. So how to implement it using JS?

The implementation code is as follows:

function passwordLevel(password) {
 var Modes = 0;
 for (i = 0; i < password.length; i++) {
 Modes |= CharMode(password.charCodeAt(i));
 }
 return bitTotal(Modes);
 //CharMode函数
 function CharMode(iN) {
 if (iN >= 48 && iN <= 57)//数字
  return 1;
 if (iN >= 65 && iN <= 90) //大写字母
  return 2;
 if ((iN >= 97 && iN <= 122) || (iN >= 65 && iN <= 90))
 //大小写
  return 4;
 else
  return 8; //特殊字符
 }
 //bitTotal函数
 function bitTotal(num) {
 modes = 0;
 for (i = 0; i < 4; i++) {
  if (num & 1) modes++;
  num >>>= 1;
 }
 return modes;
 }
}
Copy after login

Use

Normal use

Usage syntax: passwordLevel(string)
Validation rules: numbers, uppercase letters, lowercase letters, special characters
Function result: Returns the number of rules contained in the password
Running example:

passwordLevel("123456") //返回1

passwordLevel("Abc'123456") //返回4

Copy after login

Use in combination with jquery.validate.js:

//添加验证方法:至少包含两种规则

$.validator.addMethod("strongPsw",function(value,element){
 if(passwordLevel(value)==1){returnfalse;}
 returntrue
},"格式不符合");
//开始验证

$(".form").validate({
 rules:{
 pwd:{
  required:true, //必填
  minlength:6, //最小长度
  maxlength:32, //最大长度
  strongPsw:true, //密码强度
 },
 repwd:{
  required:true,
  minlength:6,
  maxlength:32,
  equalTo:"#pwd" //再次填写密码需一致
 }
 }
});
Copy after login

Friends who are interested in password generation and strength detection can also refer to the online tool:

Password security online detection

Strong Password Generator

Short link (short URL) online generation tool

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. Mar 28, 2024 pm 12:50 PM

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? Apr 11, 2024 am 09:10 AM

When using Win11 system, sometimes you will encounter a prompt that requires you to enter the administrator username and password. This article will discuss how to deal with this situation. Method 1: 1. Click [Windows Logo], then press [Shift+Restart] to enter safe mode; or enter safe mode this way: click the Start menu and select Settings. Select "Update and Security"; select "Restart Now" in "Recovery"; after restarting and entering the options, select - Troubleshoot - Advanced Options - Startup Settings -&mdash

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

How much does it cost to level 1-75 on Douyin? How much does it cost to level 1-75 on Douyin? Apr 23, 2024 am 11:12 AM

1. Level 1 costs 0.5 yuan. 2. Level 2 costs 1 yuan. 3. Level 3 costs 2 yuan. 4. Level 4 costs 3 yuan. 5. Level 5 costs 5 yuan. 6. Level 6 costs 7 yuan. 7. Level 7 costs 9 yuan. 8. Level 8 costs 13 yuan. 9. Level 9 costs 18 yuan. 10. Level 10 costs 24 yuan. 11. Level 11 costs 32 yuan. 12. Level 12 costs 42 yuan. 13. Level 13 costs 57 yuan. 14. Level 14 costs 73 yuan. 15. Level 15 costs 97 yuan. 16. Level 16 costs 130 yuan.

How to set router WiFi password using mobile phone (using mobile phone as tool) How to set router WiFi password using mobile phone (using mobile phone as tool) Apr 24, 2024 pm 06:04 PM

Wireless networks have become an indispensable part of people's lives in today's digital world. Protecting the security of personal wireless networks is particularly important, however. Setting a strong password is key to ensuring that your WiFi network cannot be hacked by others. To ensure your network security, this article will introduce in detail how to use your mobile phone to change the router WiFi password. 1. Open the router management page - Open the router management page in the mobile browser and enter the router's default IP address. 2. Enter the administrator username and password - To gain access, enter the correct administrator username and password in the login page. 3. Navigate to the wireless settings page - find and click to enter the wireless settings page, in the router management page. 4. Find the current Wi

Tutorial on changing wifi password on mobile phone (simple operation) Tutorial on changing wifi password on mobile phone (simple operation) Apr 26, 2024 pm 06:25 PM

Wireless networks have become an indispensable part of our lives with the rapid development of the Internet. In order to protect personal information and network security, it is very important to change your wifi password regularly, however. To help you better protect your home network security, this article will introduce you to a detailed tutorial on how to use your mobile phone to change your WiFi password. 1. Understand the importance of WiFi passwords. WiFi passwords are the first line of defense to protect personal information and network security. In the Internet age, understanding its importance can better understand why passwords need to be changed regularly. 2. Confirm that the phone is connected to wifi. First, make sure that the phone is connected to the wifi network whose password you want to change before changing the wifi password. 3. Open the phone’s settings menu and enter the phone’s settings menu.

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

See all articles