def get_space(cls, username): """获取硬盘空间大小""" for user_file in os.listdir(cls.user_path): if common.create_md5(username) == user_file: user_file_path = os.path.join(cls.user_path, user_file) user_info = pickle.load(open(user_file_path, 'rb')) return user_info[2]
def login(self): try: # user_info_list = self.user_info() for user in os.listdir(self.user_path): if common.create_md5(self.username) == user: user_home_info = os.path.join(self.user_path, user) user_info = pickle.load(open(user_home_info, 'rb')) if self.username == user_info[0]: if common.create_md5(self.password) == user_info[1]: print('\033[32;1m login success\033[0m') return True else: print('\033[31;1m username or password is fail\033[0m') except FileNotFoundError: print('user is not exist')
def register(self): try: user_list = [] user_info_list = self.user_info() for user in user_info_list: user_list.append(user[0]) if self.username in user_list: print('用户名已存在') else: md5_password = common.create_md5(self.password) # 对用户的密码进行md5后存储 user_info = [self.username, md5_password] # 保存用户信息的文件,以用户名的md5值命名 file_path = os.path.join(self.user_path, common.create_md5(self.username)) pickle.dump(user_info, open(file_path, 'wb')) self.ftp_dir() except TypeError: print('注册失败')
def login(self): try: user_info_list = self.user_info() self_user_info = [self.username, common.create_md5(self.password)] if self_user_info in user_info_list: print('login success') return True else: print('username or password is fail') except FileNotFoundError: print('user is not exist')