Lelee ike okwuntughe na Javascript ma ọ bụ jQuery na nkwupụta oge niile (site na ihe atụ nke akụkụ nkesa, kwa!)
Anọ m na-eme nyocha na ịchọta ezigbo ihe atụ nke onye nyocha Paswọdu na-eji JavaScript na Okwu mgbe nile (regex). N'ime ngwa n'ọrụ m, anyị na-eme post azụ iji nyochaa ike okwuntughe na ọ naghị adị mma maka ndị ọrụ anyị.
Gịnị bụ Regex?
Okwu mgbe niile bụ usoro mkpụrụedemede na-akọwa usoro ọchụchọ. Ọtụtụ mgbe, a na-eji usoro ndị dị otú ahụ eme ihe site na iji eriri ịchọ algorithms chọta or chọta ma dochie arụmọrụ na eriri, ma ọ bụ maka nkwado ndenye.
O doro anya na isiokwu a agaghị akụziri gị okwu mgbe niile. Naanị ịmara na ikike iji Nkwupụta Okwu Oge niile ga-eme ka mmepe gị dị mfe ka ị na-achọ ụkpụrụ na ederede. Ọ dịkwa mkpa iburu n'uche na ọtụtụ asụsụ mmepe emeela ka kachasị mma iji okwu eme ihe… yabụ karịa ịkọwapụta na ịchọpụta eriri na-aga, Regex na-adịkarị ngwa ngwa ma sava na ndị ahịa.
Achọrọ m web ahụ ntakịrị oge tupu achọta m ihe atụ nke ụfọdụ nnukwu okwu oge niile na-achọ nchikota ogologo, mkpụrụedemede na akara. Agbanyeghị, koodu ahụ dị ntakịrị karịa maka uto m ma ahaziri maka .NET. Ya mere, m mere ka koodu ahụ dị mfe ma tinye ya na Javascript. Nke a na-eme ka ọ kwado ike paswọọdụ ozugbo na ihe nchọgharị onye ahịa tupu ikesa ya azụ… ma nye ụfọdụ nzaghachi nye onye ọrụ na ike paswọọdụ.
Pịnye A Paswọdu
Na nke ọ bụla strok nke keyboard, paswọọdụ na-anwale megide mgbe okwu na mgbe ahụ nzaghachi na-nyere onye ọrụ na a na-adịru n'okpuru ya.
Ọrụ ike nke okwuntughe Javascript
The Okwu mgbe nile rụọ ọrụ dị egwu nke ibelata ogologo koodu ahụ. Ọrụ Javascript a na-enyocha ike okwuntughe yana ma imebi ya ọ dị mfe, ọkara, siri ike, ma ọ bụ nke siri ike ịkọ nkọ. Ka onye ahụ na-edepụta ihe, ọ na-egosiputa ndụmọdụ maka ịgba ya ume ka ọ dị ike. Ọ na-akwado paswọọdụ dabere na:
- ogologo - Ọ bụrụ na ogologo dị n'okpuru ma ọ bụ karịa mkpụrụedemede 8.
- Akpa agwakọta – Ọ bụrụ na okwuntughe nwere ma mkpụrụedemede ukwu na nke obere.
- Ọnụ Ọgụgụ – Ọ bụrụ na paswọọdụ gụnyere nọmba.
- Ndi Puru iche - Ọ bụrụ na paswọọdụ gụnyere mkpụrụedemede pụrụ iche.
Ọrụ ahụ na-egosiputa ihe isi ike yana ụfọdụ ndụmọdụ maka imesi okwuntu ike n'ihu.
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;
}
}
Ọ bụrụ na-amasị gị imelite agba nke ọnụ ọnụ ahụ, ị nwere ike ime nke ahụ nke ọma site na imelite koodu ahụ ka emechara. // Return results
akara.
// 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";
}
Ọrụ ike ike jQuery Paswọdu
Site na jQuery, anyị ekwesịghị iji nwelite ihe ntinye dee fọm ahụ:
<form>
<label for="password">Enter password:</label>
<input type="password" id="password">
<p id="password-strength"></p>
</form>
Anyị nwekwara ike gbanwee agba nke ozi ma ọ bụrụ na-amasị anyị.
$(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');
}
});
});
Harding Paswọdu gị arịrịọ
Ọ dị mkpa na ị gaghị akwado naanị nrụpụta okwuntughe n'ime Javascript gị. Nke a ga-enyere onye ọ bụla nwere ngwaọrụ mmepe ihe nchọgharị aka ịgafe ederede wee jiri paswọọdụ ọ bụla masịrị ya. Ị ga-eji nlele n'akụkụ ihe nkesa eme ihe mgbe niile iji kwado ike okwuntughe tupu ịchekwa ya n'elu ikpo okwu gị.
Ọrụ PHP maka ike okwuntughe
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";
}
}
Ọrụ Python Maka Ike Paswọdu
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"
Ọrụ C # Maka Ike Okwuntughe
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";
}
}
Ọrụ Java Maka Ike Paswọdu
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";
}
}
Ma ọ bụrụ na ị na-achọ nnọọ a oké okwuntughe generator, M wuru a mara mma obere online ngwá ọrụ maka na.