js实现的密码强度检测的两个实例
第一个实例
这段JavaScript代码比较实用,它完成用户注册时判断用户输入密码的强度,分强、弱、中三等级,它可以根据用户输入的密码显示对应的密码强弱等级,方便用户改进输入。
实现代码:
<code class="language-html"> <title>JS判断密码强度</title> <script language="javascript"> //判断输入密码的类型 function CharMode(iN){ if (iN>=48 && iN <=57) //数字 return 1; if (iN>=65 && iN <=90) //大写 return 2; if (iN>=97 && iN <=122) //小写 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; } //返回强度级别 function checkStrong(sPW){ if (sPW.length<=4) return 0; //密码太短 Modes=0; for (i=0;i<sPW.length;i++){ //密码模式 Modes|=CharMode(sPW.charCodeAt(i)); } return bitTotal(Modes); } //显示颜色 function pwStrength(pwd){ O_color="#eeeeee"; L_color="#FF0000"; M_color="#FF9900"; H_color="#33CC00"; if (pwd==null||pwd==''){ Lcolor=Mcolor=Hcolor=O_color; } else{ S_level=checkStrong(pwd); switch(S_level) { case 0: Lcolor=Mcolor=Hcolor=O_color; case 1: Lcolor=L_color; Mcolor=Hcolor=O_color; break; case 2: Lcolor=Mcolor=M_color; Hcolor=O_color; break; default: Lcolor=Mcolor=Hcolor=H_color; } } document.getElementById("strength_L").style.background=Lcolor; document.getElementById("strength_M").style.background=Mcolor; document.getElementById("strength_H").style.background=Hcolor; return; } </script> <form name="form1" action=""> 密码:<input type="password" size="8" onkeyup="pwStrength(this.value)" onblur="pwStrength(this.value)"> <br>密码强度: <table width="210" border="1" cellspacing="0" cellpadding="1" bordercolor="#eeeeee" height="22" style="display:inline"> <tr align="center" bgcolor="#f5f5f5"> <td width="33%" id="strength_L">弱</td> <td width="33%" id="strength_M">中</td> <td width="33%" id="strength_H">强</td> </tr> </table> </form> </code>
在线运行
第二个实例:
<code class="language-javascript"> function AuthPasswd(string) { if (string.length >= 6) { if (/[a-zA-Z]+/.test(string) && /[0-9]+/.test(string) && /\W+\D+/.test(string)) { noticeAssign(1); } else if (/[a-zA-Z]+/.test(string) || /[0-9]+/.test(string) || /\W+\D+/.test(string)) { if (/[a-zA-Z]+/.test(string) && /[0-9]+/.test(string)) { noticeAssign( - 1); } else if (/\[a-zA-Z]+/.test(string) && /\W+\D+/.test(string)) { noticeAssign( - 1); } else if (/[0-9]+/.test(string) && /\W+\D+/.test(string)) { noticeAssign( - 1); } else { noticeAssign(0); } } } else { noticeAssign(null); } } function noticeAssign(num) { if (num == 1) { $('#weak').css({ backgroundColor: '#009900' }); $('#middle').css({ backgroundColor: '#009900' }); $('#strength').css({ backgroundColor: '#009900' }); $('#strength').html('很强'); $('#middle').html(''); $('#weak').html(''); } else if (num == -1) { $('#weak').css({ backgroundColor: '#ffcc33' }); $('#middle').css({ backgroundColor: '#ffcc33' }); $('#strength').css({ backgroundColor: '' }); $('#weak').html(''); $('#middle').html('中'); $('#strength').html(''); } else if (num == 0) { $('#weak').css({ backgroundColor: '#dd0000' }); $('#middle').css({ backgroundColor: '' }); $('#strength').css({ backgroundColor: '' }); $('#weak').html('弱'); $('#middle').html(''); $('#strength').html(''); } else { $('#weak').html(' '); $('#middle').html(' '); $('#strength').html(' '); $('#weak').css({ backgroundColor: '' }); $('#middle').css({ backgroundColor: '' }); $('#strength').css({ backgroundColor: '' }); } } /</code>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

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.

This article will explore how to solve the problem of wrong password, especially the need to be careful when dealing with BitLocker warnings. This warning is triggered when an incorrect password is entered multiple times in BitLocker to unlock the drive. Usually, this warning occurs because the system has a policy that limits incorrect login attempts (usually three login attempts are allowed). In this case, the user will receive an appropriate warning message. The complete warning message is as follows: The password entered is incorrect. Please note that continuously entering incorrect passwords will cause the account to be locked. This is to protect the security of your data. If you need to unlock your account, you will need to use a BitLocker recovery key. The password is incorrect, beware the BitLocker warning you receive when you log in to your computer

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Passkey is a more advanced and secure way to log in and can be used with a Microsoft account. This article will guide you how to use Passkey in your Microsoft account, introduce its advantages and the differences with passwords. Before we get into the details, we emphasize that if you frequently forget your passwords or need to log in quickly, Passkey will generally be better for you. What is Passkey? How are they different from passwords? Passwords are an advanced and secure authentication method that can replace traditional password logins. Each application has a unique key, ensuring security and preventing threats like phishing. Users can confirm their identity via email and password, or use facial recognition, fingerprint or security key

Today I would like to introduce to you an article published by MIT last week, using GPT-3.5-turbo to solve the problem of time series anomaly detection, and initially verifying the effectiveness of LLM in time series anomaly detection. There is no finetune in the whole process, and GPT-3.5-turbo is used directly for anomaly detection. The core of this article is how to convert time series into input that can be recognized by GPT-3.5-turbo, and how to design prompts or pipelines to let LLM solve the anomaly detection task. Let me introduce this work to you in detail. Image paper title: Largelanguagemodelscanbezero-shotanomalydete

How to unlock iPhone if you forget password In modern society, mobile phones have become an indispensable part of our lives. Among mobile phones, Apple mobile phones are chosen and trusted by the majority of users due to their stability and security. However, sometimes we also encounter some problems, such as forgetting the iPhone password we set. How to unlock your iPhone if you forget your password? Below we will discuss several common unlocking methods. The first method is to unlock it through the "Retrieve Phone Password" function. First, we want to make sure the phone is connected to the Internet. Then,
