示例#1
0
def auth(client_socket, args):
    """
    客户端用户登录认证模块
    :param client_socket: 客户端socket对象
    :param args: 用户发送过来的数据 ex: "auth|test|a7470858e79c282bc2f6adfd831b132672dfd1224c1e78cbf5bcd057"
    :return: 3状态结果:  0: 认证成功 , 1:用户不存在 , 2:用户被锁 3:用户名或密码错误
    """
    recv_data_list = args.split("|")
    username = recv_data_list[1]
    passwd = recv_data_list[2]
    # 将传入的用户对象实例化
    client_user = Users(username)
    # 若用户存在
    if client_user.exists:
        # 验证成功
        if client_user.user_auth(passwd):
            auth_status = "0"
            # 加载用户的磁盘配额信息
            user_space = "{0}|{1}".format(client_user.totalspace,
                                          client_user.usedspace)
        # 验证失败
        elif client_user.isdel == 1:
            # 用户已经删除,不存在
            auth_status = "1"
        elif client_user.islocked == 1:
            # 用户被锁了
            auth_status = "2"
        else:
            # 密码错误
            auth_status = "3"
    else:
        auth_status = "1"

    # 认证结果发送给客户端
    client_socket.send(bytes(auth_status, encoding='utf8'))

    # 认证成功则将用户空间信息发送到客户端
    if auth_status == "0":
        client_socket.send(bytes(user_space, 'utf8'))
    return client_user
示例#2
0
def auth(client_socket, args):
    """
    客户端用户登录认证模块
    :param client_socket: 客户端socket对象
    :param args: 用户发送过来的数据 ex: "auth|test|a7470858e79c282bc2f6adfd831b132672dfd1224c1e78cbf5bcd057"
    :return: 3状态结果:  0: 认证成功 , 1:用户不存在 , 2:用户被锁 3:用户名或密码错误
    """
    recv_data_list = args.split("|")
    username = recv_data_list[1]
    passwd = recv_data_list[2]
    # 将传入的用户对象实例化
    client_user = Users(username)
    # 若用户存在
    if client_user.exists:
        # 验证成功
        if client_user.user_auth(passwd):
            auth_status = "0"
            # 加载用户的磁盘配额信息
            user_space = "{0}|{1}".format(client_user.totalspace, client_user.usedspace)
        # 验证失败
        elif client_user.isdel == 1:
            # 用户已经删除,不存在
            auth_status = "1"
        elif client_user.islocked == 1:
            # 用户被锁了
            auth_status = "2"
        else:
            # 密码错误
            auth_status = "3"
    else:
        auth_status = "1"

    # 认证结果发送给客户端
    client_socket.send(bytes(auth_status, encoding='utf8'))

    # 认证成功则将用户空间信息发送到客户端
    if auth_status == "0":
        client_socket.send(bytes(user_space, 'utf8'))
    return client_user
示例#3
0
文件: main.py 项目: pytos/MyProjects
    trycount = 3
    count = 0

    while count < trycount:
        print(MENU)
        username = common.inputs("用户名: ").lower()
        passwd = common.inputs("密码: ")
        # 实例化一个用户对象
        userobj = Users(username)
        if not userobj.exists:
            print("用户名或密码错误!\n")
            common.write_log("用户{0}登录, 用户名不存在".format(username), "info", "op")
            count += 1
            continue
        else:
            auth_stat = userobj.user_auth(passwd)
            if not auth_stat:
                common.write_log("用户{0}登录, 用户名密码不正确".format(username), "info", "op")
                print("登录失败!用户名或密码错误!")
                count += 1
                continue
            else:
                # 登录成功
                common.write_log("用户{0}登录, 登录成功!".format(username), "info", "op")
                print("欢迎登录堡垒机精简版(v1.0)\n")
                exit_flag = False
                while not exit_flag:
                    command_str = input("[ {username} ] (q to exit):\> ".format(username=username))
                    common.write_log("用户{0}执行命令{1}".format(username, command_str), "info", "op")
                    if command_str.strip().lower() == "q":
                        sys.exit(0)