Tôi muốn người dùng sử dụng các ký tự đặc biệt khi tạo mật khẩu. [Ít nhất 1] Ví dụ:
special_character= list[string.punctuation]
password=input["enter password:"]
if any[i not in password for i in special_character]:
print["You should add a special character for creating strong password!"]
Nó sẽ như thế này nhưng nó không hoạt động. Bạn có thể giúp tôi được không? Cảm ơn.
hỏi ngày 17 tháng 4 lúc 18:18Apr 17 at 18:18
Chỉ cần sử dụng all[...]
, hoặc cách khác, sử dụng not any[...]
nhưng không có not
trong danh sách hiểu [điều này tốt hơn vì not
được chạy ít lần hơn về tổng thể, làm cho nó hiệu quả hơn một chút]. Đây là những gì mã sẽ trông như thế nào:
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
Đã trả lời ngày 17 tháng 4 lúc 18:21Apr 17 at 18:21
LecdilecdiLecdi
2.0062 huy hiệu vàng4 Huy hiệu bạc17 Huy hiệu đồng2 gold badges4 silver badges17 bronze badges
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
81special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
83special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
84special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
85special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
87special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
89special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
92Bạn có thể sử dụng các ký tự đặc biệt trong mật khẩu không?
- Mật khẩu sẽ tận dụng số lượng ký tự tối đa cho phép của mỗi tài khoản. Nó phải chứa tất cả các ký tự mà tài khoản cho phép, ví dụ: Số, dấu câu và ký tự đặc biệt.
- Các nhân vật đặc biệt có được phép trong Python không?
- Python3. Một định danh trong Python không thể sử dụng bất kỳ biểu tượng đặc biệt nào như!, @, #, $, %, V.v.
- Cải thiện bài viết
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!
Lưu bài viết
Hãy để lấy mật khẩu làm kết hợp các ký tự chữ và số cùng với các ký tự đặc biệt và kiểm tra xem mật khẩu có hợp lệ hay không với sự trợ giúp của một số điều kiện. Naive Method [Without using Regex].
Điều kiện cho một mật khẩu hợp lệ là:
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
2special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
4special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
5special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
6special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
7special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
6special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
9special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
6Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!1
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!2
Nên có ít nhất một số.
Nên có ít nhất một ký tự chữ hoa và một ký tự viết thường.
Password is valid3
Password is valid4
Password is valid5
Password is valid6
Password is valid7
Password is valid3
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!4
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 Password is valid.1
Nên có ít nhất một biểu tượng đặc biệt.
Password is valid3
Password is valid4
Password is valid5
all[...]
1Password is valid7
Password is valid3
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!4
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 Password is valid.1
Nên dài từ 6 đến 20 ký tự.
Password is valid3
Password is valid4
Password is valid5
not any[...]
9Password is valid7
Password is valid3
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!4
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 Password is valid.1
Chúng tôi có thể kiểm tra xem một chuỗi đã cho có đủ điều kiện để trở thành mật khẩu hoặc không sử dụng nhiều cách.
Phương pháp số 1: Phương pháp ngây thơ [không sử dụng Regex].
Password is valid3
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!4
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 Password is valid.1
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
not
not any[...]
0def
7not any[...]
2 not any[...]
3__Password is valid3
Password is valid4
Password is valid5
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
05Password is valid7
Password is valid3
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!4
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 Password is valid.1
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
not
not any[...]
0special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
15not any[...]
4 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
2not any[...]
2Password is valid3
Password is valid4
Password is valid5
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
25Password is valid7
Password is valid3
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!4
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 Password is valid.1
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
33Password is valid3
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
35 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
36def
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
38special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
40special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
42special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
45Password is valid3
Password is valid4
Password is valid5
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
49Password is valid7
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
52Password is valid2
Password is valid3
Password is valid4
Password is valid5
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
57Password is valid7
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
60special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
63Password is valid2
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
66Output:
Password is valid
Mã này đã sử dụng các chức năng Boolean để kiểm tra xem tất cả các điều kiện có được thỏa mãn hay không. Chúng tôi thấy rằng mặc dù độ phức tạp của mã là cơ bản, độ dài là đáng kể. & NBSP; Phương pháp #2: Sử dụng Regex
Method
#2: Using regex
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
67 Phương pháp mô -đun Regex tạo ra một đối tượng Regex, giúp thực thi các hàm regex lên biến PAT. Sau đó, chúng tôi kiểm tra xem mẫu được xác định bởi PAT có được theo sau bởi chuỗi đầu vào passwd không. Nếu vậy, phương thức tìm kiếm trả về true, cho phép mật khẩu hợp lệ.special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
68 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
69def
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
38special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
40special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
42special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
777____13 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
79special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
81special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
83special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
84special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
85special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
87special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
89special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
92Password is valid3
Password is valid4
Password is valid5
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
96Password is valid7
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
52Password is valid2
Password is valid3
Password is valid4
Password is valid5
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!04
Password is valid7
Input : Geek12# Output : Password is valid. Input : asd123 Output : Invalid Password !!8
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
60special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
3 special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
63Password is valid2
special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
1special_characters = list[string.punctuation]
password = input["Enter password: "]
if not any[i in password for i in special_characters]:
print["You should add a special character for creating strong password!"]
66Output:
Password is valid.