python - TypeError 的 Python PWManager 问题:“NoneType”类型的对象没有 len()
问题描述
输入密码后出现以下错误:
添加密码功能后出现此问题。如果我在没有密码功能的情况下运行代码,它将加密并存储
TypeError:“NoneType”类型的对象没有 len()
该程序应该加密密码并存储它。
任何帮助将不胜感激。
谢谢
import re
def encrypt(data, shift):
encrypted = ""
for i in range(len(data)):
char = data[i]
if (char.isupper()):
encrypted += chr((ord(char) + shift - 65 % 26 + 65))
elif (char.islower()):
encrypted += chr((ord(char) + shift - 97) % 26 + 97)
elif (char.isdigit()):
number = (int(char) + shift) % 10
encrypted += str(number)
else:
encrypted += char
return encrypted
def password_check(password):
numerics = '0123456789'
capital_alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lowercase_alphabet = 'abcdefghigklmnopqrstuvwxyz'
special_chars = '#?,!'
sum = 0;
x = 0;
y = 0;
z = 0;
h = 0
while sum != 4:
while len(password) < 10:
password = input('\nPlease Enter a Correct Password rakam')
for i in range(len(password)):
if password[i] in numerics:
x = 1
elif password[i] in capital_alphabets:
y = 1
elif password[i] in special_chars:
z = 1
elif re.search("MIT", password):
h = 1
sum = x + y + z + h
if sum != 4:
password = input('\nThe Password Must Meet the following CarteriaPlease enter a correct password')
else:
print('\nPassword is accepted')
menue = ""
while menue != '1' or menue != '2':
menue = input("would you like to save a new password or view old ones"
"\n1. inputnew password"
"\n2. view passwords"
"\n3. exit")
if menue == '1':
accountname = input("Enter the name of your account")
password = password_check(input("Enter you Password"))
shift = 5
file = open("Savedpasswords.txt", "a")
file.write(encrypt(accountname,shift)+";|"+encrypt(password,shift)+"\n")
file.close()
if menue == '2':
file = open("Savedpasswords.txt", "r")
print("accountname\tpassword")
for i in file:
data = i.split(";|")
print(data)
if menue == '3':
exit()
Password is accepted
Traceback (most recent call last):
File "/Users/hamzaabutaleb/PycharmProjects/PasswordManager/Main.py", line 66, in <module>
file.write(encrypt(accountname,shift)+";|"+encrypt(password,shift)+"\n")
File "/Users/hamzaabutaleb/PycharmProjects/PasswordManager/Main.py", line 4, in encrypt
for i in range(len(data)):
TypeError: object of type 'NoneType' has no len()
Process finished with exit code 1
解决方案
问题在这里:
password = password_check(input("Enter you Password"))
由于password_check
没有显式返回任何内容,因此它隐式返回None
,因此这具有设置password
为的效果None
。要修复它,请将其更改为:
password = input("Enter you Password")
password_check(password)
但是,如果您希望password_check
能够提示输入新密码,则应将其更改为返回密码,在这种情况下,您将返回分配 to 的password_check
结果password
。
推荐阅读
- connector - PowerApps 中的连接器是什么
- c# - 修改方法逻辑 MOQ
- java - Spring @RequestScope 是否有 Micronaut 类似物?
- django - 一个表过滤器对我来说工作正常,但是在这里我需要在 django 中过滤两个不起作用的表过滤器
- android - 当 Fragment B 进入时,导致 Fragment A 消失的导航架构组件
- java - Java中如何使用冒泡排序对多维数组进行排序
- webdriver-io - Cucumber - 如何获取当前正在执行的场景标签
- python - autosklearn.regression.AutoSklearnRegressor 中的参数 'ensemble_size' 似乎没有任何作用,如何正确使用呢?
- nuxt.js - nuxt.js 的多个入口点
- python-3.x - 导入tensorflow,keras时导入错误