Yang'anani Mphamvu Yachinsinsi ndi JavaScript kapena jQuery ndi Mawu Okhazikika (Ndi Zitsanzo Zam'mbali Za Seva, Nazonso!)
Ndinkafufuza kuti ndipeze chitsanzo chabwino cha Chinsinsi cha Mphamvu Zachinsinsi chomwe chimagwiritsa ntchito JavaScript ndi Mawu Otsimikizika (regex). Mukugwiritsa ntchito kwanga, timalemba positi kuti titsimikizire mphamvu ya mawu achinsinsi ndipo ndizosokoneza kwa ogwiritsa ntchito.
Regex ndi chiyani?
Mawu okhazikika ndi mndandanda wazinthu zomwe zimatanthauzira kafukufuku. Nthawi zambiri, zoterezi zimagwiritsidwa ntchito ndi njira zosakira zingwe za kupeza or pezani ndikusintha ntchito zingwe, kapena kutsimikizira kolowera.
Nkhaniyi sikuyenera kukuphunzitsani mayankhulidwe wamba. Ingodziwa kuti kutha kugwiritsa ntchito Mawu Okhazikika kudzachepetsa kwambiri chitukuko chanu mukamasanthula zolemba. Ndikofunikanso kudziwa kuti zilankhulo zambiri zachitukuko zathandiza kuti anthu azigwiritsa ntchito mawu mofananira… m'malo mongofufuza ndi zingwe pang'onopang'ono, Regex imafulumira kwambiri pa seva komanso mbali ya kasitomala.
Ndinafufuza pa intaneti pang'ono ndisanapeze chitsanzo za Mawu ena abwino Okhazikika omwe amayang'ana kuphatikiza kwa utali, zilembo, ndi zizindikilo. Komabe, kachidindo anali pang'ono mopambanitsa kwa kukoma kwanga ndi zogwirizana .NET. Chifukwa chake ndidasinthira kachidindo ndikuyika mu JavaScript. Izi zimapangitsa kutsimikizira mphamvu ya mawu achinsinsi munthawi yeniyeni pa osatsegula a kasitomala musanayitumizenso… ndipo imapereka mayankho kwa wogwiritsa ntchito pamphamvu yachinsinsi.
Lembani A Achinsinsi
Pogwiritsa ntchito kiyibodi iliyonse, mawu achinsinsi amayesedwa motsutsana ndi mawu wamba ndiyeno mayankho amaperekedwa kwa wogwiritsa ntchito munthawi yake.
Ntchito Yamphamvu Yachinsinsi ya JavaScript
The Mawu Otsimikizika chitani ntchito yabwino kwambiri yochepetsera utali wa code. Ntchito ya JavaScript iyi imayang'ana mphamvu ya mawu achinsinsi komanso ngati kufooketsa ndikosavuta, pakati, kovuta, kapena kovuta kwambiri kulingaliridwa. Pamene munthu akuyimira, amasonyeza malangizo olimbikitsa kuti akhale amphamvu. Imatsimikizira mawu achinsinsi kutengera:
- utali - Ngati kutalika kuli pansi kapena kupitilira zilembo 8.
- Mlandu Wosakanikirana - Ngati mawu achinsinsi ali ndi zilembo zazikulu ndi zazing'ono.
- manambala - Ngati mawu achinsinsi ali ndi manambala.
- Anthu Odziwika Kwambiri - Ngati mawu achinsinsi ali ndi zilembo zapadera.
Ntchitoyi ikuwonetsa zovuta komanso maupangiri ena owumitsa mawu achinsinsi.
function checkPasswordStrength(password) {
// Initialize variables
var strength = 0;
var tips = "";
// Check password length
if (password.length < 8) {
tips += "Make the password longer. ";
} else {
strength += 1;
}
// Check for mixed case
if (password.match(/[a-z]/) && password.match(/[A-Z]/)) {
strength += 1;
} else {
tips += "Use both lowercase and uppercase letters. ";
}
// Check for numbers
if (password.match(/\d/)) {
strength += 1;
} else {
tips += "Include at least one number. ";
}
// Check for special characters
if (password.match(/[^a-zA-Z\d]/)) {
strength += 1;
} else {
tips += "Include at least one special character. ";
}
// Return results
if (strength < 2) {
return "Easy to guess. " + tips;
} else if (strength === 2) {
return "Medium difficulty. " + tips;
} else if (strength === 3) {
return "Difficult. " + tips;
} else {
return "Extremely difficult. " + tips;
}
}
Ngati mukufuna kusintha mtundu wa nsonga, mutha kuchita izi pokonzanso kachidindo pambuyo pa // Return results
mzere.
// Get the paragraph element
var strengthElement = document.getElementById("passwordStrength");
// Return results
if (strength < 2) {
strengthElement.textContent = "Easy to guess. " + tips;
strengthElement.style.color = "red";
} else if (strength === 2) {
strengthElement.textContent = "Medium difficulty. " + tips;
strengthElement.style.color = "orange";
} else if (strength === 3) {
strengthElement.textContent = "Difficult. " + tips;
strengthElement.style.color = "black";
} else {
strengthElement.textContent = "Extremely difficult. " + tips;
strengthElement.style.color = "green";
}
jQuery Achinsinsi Mphamvu Ntchito
Ndi jQuery, sitiyenera kulemba fomuyo ndi zosintha za oninput:
<form>
<label for="password">Enter password:</label>
<input type="password" id="password">
<p id="password-strength"></p>
</form>
Tikhozanso kusintha mtundu wa mauthenga ngati tikufuna.
$(document).ready(function() {
$('#password').on('input', function() {
var password = $(this).val();
var strength = 0;
var tips = "";
// Check password length
if (password.length < 8) {
tips += "Make the password longer. ";
} else {
strength += 1;
}
// Check for mixed case
if (password.match(/[a-z]/) && password.match(/[A-Z]/)) {
strength += 1;
} else {
tips += "Use both lowercase and uppercase letters. ";
}
// Check for numbers
if (password.match(/\d/)) {
strength += 1;
} else {
tips += "Include at least one number. ";
}
// Check for special characters
if (password.match(/[^a-zA-Z\d]/)) {
strength += 1;
} else {
tips += "Include at least one special character. ";
}
// Update the text and color based on the password strength
var passwordStrengthElement = $('#password-strength');
if (strength < 2) {
passwordStrengthElement.text("Easy to guess. " + tips);
passwordStrengthElement.css('color', 'red');
} else if (strength === 2) {
passwordStrengthElement.text("Medium difficulty. " + tips);
passwordStrengthElement.css('color', 'orange');
} else if (strength === 3) {
passwordStrengthElement.text("Difficult. " + tips);
passwordStrengthElement.css('color', 'black');
} else {
passwordStrengthElement.text("Extremely difficult. " + tips);
passwordStrengthElement.css('color', 'green');
}
});
});
Kuumitsa Pempho Lanu Labwino
Ndikofunika kuti musamangotsimikizira kupanga mawu achinsinsi mu JavaScript yanu. Izi zitha kuthandiza aliyense yemwe ali ndi zida zopangira msakatuli kuti adutse script ndikugwiritsa ntchito mawu achinsinsi omwe angafune. Muyenera kugwiritsa ntchito cheke cha mbali zonse za seva kuti mutsimikizire mphamvu ya mawu achinsinsi musanayisunge papulatifomu yanu.
PHP Ntchito Yamphamvu Yachinsinsi
function checkPasswordStrength($password) {
// Initialize variables
$strength = 0;
// Check password length
if (strlen($password) < 8) {
return "Easy to guess";
} else {
$strength += 1;
}
// Check for mixed case
if (preg_match("/[a-z]/", $password) && preg_match("/[A-Z]/", $password)) {
$strength += 1;
}
// Check for numbers
if (preg_match("/\d/", $password)) {
$strength += 1;
}
// Check for special characters
if (preg_match("/[^a-zA-Z\d]/", $password)) {
$strength += 1;
}
// Return strength level
if ($strength < 2) {
return "Easy to guess";
} else if ($strength === 2) {
return "Medium difficulty";
} else if ($strength === 3) {
return "Difficult";
} else {
return "Extremely difficult";
}
}
Ntchito ya Python Kwa Mphamvu Zachinsinsi
def check_password_strength(password):
# Initialize variables
strength = 0
# Check password length
if len(password) < 8:
return "Easy to guess"
else:
strength += 1
# Check for mixed case
if any(char.islower() for char in password) and any(char.isupper() for char in password):
strength += 1
# Check for numbers
if any(char.isdigit() for char in password):
strength += 1
# Check for special characters
if any(not char.isalnum() for char in password):
strength += 1
# Return strength level
if strength < 2:
return "Easy to guess"
elif strength == 2:
return "Medium difficulty"
elif strength == 3:
return "Difficult"
else:
return "Extremely difficult"
C # Ntchito Yamphamvu Yachinsinsi
public string CheckPasswordStrength(string password) {
// Initialize variables
int strength = 0;
// Check password length
if (password.Length < 8) {
return "Easy to guess";
} else {
strength += 1;
}
// Check for mixed case
if (password.Any(char.IsLower) && password.Any(char.IsUpper)) {
strength += 1;
}
// Check for numbers
if (password.Any(char.IsDigit)) {
strength += 1;
}
// Check for special characters
if (password.Any(ch => !char.IsLetterOrDigit(ch))) {
strength += 1;
}
// Return strength level
if (strength < 2) {
return "Easy to guess";
} else if (strength == 2) {
return "Medium difficulty";
} else if (strength == 3) {
return "Difficult";
} else {
return "Extremely difficult";
}
}
Ntchito ya Java Yamphamvu Yachinsinsi
public String checkPasswordStrength(String password) {
// Initialize variables
int strength = 0;
// Check password length
if (password.length() < 8) {
return "Easy to guess";
} else {
strength += 1;
}
// Check for mixed case
if (password.matches(".*[a-z].*") && password.matches(".*[A-Z].*")) {
strength += 1;
}
// Check for numbers
if (password.matches(".*\\d.*")) {
strength += 1;
}
// Check for special characters
if (password.matches(".*[^a-zA-Z\\d].*")) {
strength += 1;
}
// Return strength level
if (strength < 2) {
return "Easy to guess";
} else if (strength == 2) {
return "Medium difficulty";
} else if (strength == 3) {
return "Difficult";
} else {
return "Extremely difficult";
}
}
Ndipo ngati inu mukungofuna lalikulu achinsinsi jenereta, Ine anamanga zabwino pang'ono Intaneti chida kuti.