Python实现账号密码登录

用Python实现账号密码登录

注册后哪怕重新运行,注册的账号依然存在,我们可以把账号密码进行加密分别保存到2个txt中,使用的时候将用户输入的内容进行加密,再读取txt,十分简单

代码如下

s = input('您有账号吗(有回“1”,没有回“2”):')
if s == '2':
    print('正在为您注册账号···')
    add = 0
    s = 1
    str_add = ''
    inv_str_add = ''
    bu = input('请输入您的新用户名:')
    for i in bu:
        add += ord(i)
        str_add += str(ord(i))
    for i in str_add:
        s += 1
    for i in range(1, s):
        inv_str_add += str_add[-i]
    a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
    p = input('请输入您的密码:')
    i = input('请再次输入您的密码:')
    if p==i:
        print('好的,已为您自动登录')
        e = open('用户名.txt','a')
        #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
        e.write(a1)
        e.write('\n')
        e.close()
        add = 0
        s = 1
        str_add = ''
        inv_str_add = ''
        for i in p:
            add += ord(i)
            str_add += str(ord(i))
        for i in str_add:
            s += 1
        for i in range(1, s):
            inv_str_add += str_add[-i]
        a = ('{}{}' .format(p, add + int(inv_str_add)))
        e1 = open('密码.txt','a')
        #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
        e1.write(a)
        e1.write('\n')
        e1.close()
        print(1)
    else:
        print('两次密码不一致,请重新输入')
        while True:
            print('正在为您注册账号···')
            add = 0
            s = 1
            str_add = ''
            inv_str_add = ''
            bu = input('请输入您的新用户名:')
            for i in bu:
                add += ord(i)
                str_add += str(ord(i))
            for i in str_add:
                s += 1
            for i in range(1, s):
                inv_str_add += str_add[-i]
            a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
            p = input('请输入您的密码:')
            i = input('请再次输入您的密码:')
            if p==i:
                print('好的,已为您自动登录')
                e = open('用户名.txt','a')
                #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                e.write(a1)
                e.write('\n')
                e.close()
                add = 0
                s = 1
                str_add = ''
                inv_str_add = ''
                for i in p:
                    add += ord(i)
                    str_add += str(ord(i))
                for i in str_add:
                    s += 1
                for i in range(1, s):
                    inv_str_add += str_add[-i]
                a = ('{}{}' .format(p, add + int(inv_str_add)))
                e1 = open('密码.txt','a')
                #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                e1.write(a)
                e1.write('\n')
                e1.close()
                break
                print(1)
            else:
                print('两次密码不一致,请重新输入')
if s =='1':
    add = 0
    s = 1
    str_add = ''
    inv_str_add = ''
    bu = input('请输入您的用户名:')
    for i in bu:
        add += ord(i)
        str_add += str(ord(i))
    for i in str_add:
        s += 1
    for i in range(1, s):
        inv_str_add += str_add[-i]
    d = ('{}{}' .format(bu, add + int(inv_str_add)))
    u = open('用户名.txt','r')
    h = u.read()
    if d in h:
        add = 0
        s = 1
        str_add = ''
        inv_str_add = ''
        bu = input('请输入您的密码:')
        for i in bu:
            add += ord(i)
            str_add += str(ord(i))
        for i in str_add:
            s += 1
        for i in range(1, s):
            inv_str_add += str_add[-i]
        j = ('{}{}' .format(bu, add + int(inv_str_add)))
        e1 = open('密码.txt','r')
        f = e1.read()
        e1.close()
        if j in f:
            print('登录成功!')
            print(1)
        else:
            print('密码错误')
            add = 0
            s = 1
            str_add = ''
            inv_str_add = ''
            bu = input('请再次输入::')
            for i in bu:
                add += ord(i)
                str_add += str(ord(i))
            for i in str_add:
                s += 1
            for i in range(1, s):
                inv_str_add += str_add[-i]
            qw = ('{}{}' .format(bu, add + int(inv_str_add)))
            if qw in f:
                print('登录成功')
                print(1)
            else:
                print('正在为您注册账号···')
                add = 0
                s = 1
                str_add = ''
                inv_str_add = ''
                bu = input('请输入您的新用户名:')
                for i in bu:
                    add += ord(i)
                    str_add += str(ord(i))
                for i in str_add:
                    s += 1
                for i in range(1, s):
                    inv_str_add += str_add[-i]
                y = ('{}{}' .format(bu, add + int(inv_str_add)))
                p = input('请输入您的密码:')
                i = input('请再次输入您的密码:')
                if p==i:
                    e = open('用户名.txt','a+')
                    #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                    e.write(y)
                    e.write('\n')
                    e.close()
                    add = 0
                    s = 1
                    str_add = ''
                    inv_str_add = ''
                    for i in p:
                        add += ord(i)
                        str_add += str(ord(i))
                    for i in str_add:
                        s += 1
                    for i in range(1, s):
                        inv_str_add += str_add[-i]
                    rt = ('{}{}' .format(p, add + int(inv_str_add)))
                    e1 = open('密码.txt','a+')
                    #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                    e1.write(rt)
                    e1.write('\n')
                    e1.close()
                    print(1)
                else:
                    print('两次密码不一致,请重新输入')
                    while True:
                        print('正在为您注册账号···')
                        add = 0
                        s = 1
                        str_add = ''
                        inv_str_add = ''
                        bu = input('请输入您的新用户名:')
                        for i in bu:
                            add += ord(i)
                            str_add += str(ord(i))
                        for i in str_add:
                            s += 1
                        for i in range(1, s):
                            inv_str_add += str_add[-i]
                        a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
                        p = input('请输入您的密码:')
                        i = input('请再次输入您的密码:')
                        if p==i:
                            print('好的,已为您自动登录')
                            e = open('用户名.txt','a')
                            #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                            e.write(a1)
                            e.write('\n')
                            e.close()
                            add = 0
                            s = 1
                            str_add = ''
                            inv_str_add = ''
                            for i in p:
                                add += ord(i)
                                str_add += str(ord(i))
                            for i in str_add:
                                s += 1
                            for i in range(1, s):
                                inv_str_add += str_add[-i]
                            a = ('{}{}' .format(p, add + int(inv_str_add)))
                            e1 = open('密码.txt','a')
                            #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                            e1.write(a)
                            e1.write('\n')
                            e1.close()
                            break
                            print(1)
                        else:
                            print('两次密码不一致,请重新输入')
    else:
        print('对不起,没有查询到此账号')
        n = input('您是否需要注册账号,(回答‘是’或‘否’):')
        if n =='是' :
            print('两次密码不一致,请重新输入')
            while True:
                print('正在为您注册账号···')
                add = 0
                s = 1
                str_add = ''
                inv_str_add = ''
                bu = input('请输入您的新用户名:')
                for i in bu:
                    add += ord(i)
                    str_add += str(ord(i))
                for i in str_add:
                    s += 1
                for i in range(1, s):
                    inv_str_add += str_add[-i]
                a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
                p = input('请输入您的密码:')
                i = input('请再次输入您的密码:')
                if p==i:
                    print('好的,已为您自动登录')
                    e = open('用户名.txt','a')
                    #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                    e.write(a1)
                    e.write('\n')
                    e.close()
                    add = 0
                    s = 1
                    str_add = ''
                    inv_str_add = ''
                    for i in p:
                        add += ord(i)
                        str_add += str(ord(i))
                    for i in str_add:
                        s += 1
                    for i in range(1, s):
                        inv_str_add += str_add[-i]
                    a = ('{}{}' .format(p, add + int(inv_str_add)))
                    e1 = open('密码.txt','a')
                    #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                    e1.write(a)
                    e1.write('\n')
                    e1.close()
                    break
                    print(1)
            else:
                print('两次密码不一致,请重新输入')
                while True:
                    print('正在为您注册账号···')
                    add = 0
                    s = 1
                    str_add = ''
                    inv_str_add = ''
                    bu = input('请输入您的新用户名:')
                    for i in bu:
                        add += ord(i)
                        str_add += str(ord(i))
                    for i in str_add:
                        s += 1
                    for i in range(1, s):
                        inv_str_add += str_add[-i]
                    a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
                    p = input('请输入您的密码:')
                    i = input('请再次输入您的密码:')
                    if p==i:
                        print('好的,已为您自动登录')
                        e = open('用户名.txt','a')
                        #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                        e.write(a1)
                        e.write('\n')
                        e.close()
                        add = 0
                        s = 1
                        str_add = ''
                        inv_str_add = ''
                        for i in p:
                            add += ord(i)
                            str_add += str(ord(i))
                        for i in str_add:
                            s += 1
                        for i in range(1, s):
                            inv_str_add += str_add[-i]
                        a = ('{}{}' .format(p, add + int(inv_str_add)))
                        e1 = open('密码.txt','a')
                        #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                        e1.write(a)
                        e1.write('\n')
                        e1.close()
                        break
                        print(1)
                    else:
                        print('两次密码不一致,请重新输入')
        else:
            while True:
                add = 0
                s = 1
                str_add = ''
                inv_str_add = ''
                bu = input('请输入 用户名:')
                for i in bu:
                    add += ord(i)
                    str_add += str(ord(i))
                for i in str_add:
                    s += 1
                for i in range(1, s):
                    inv_str_add += str_add[-i]
                d = ('{}{}' .format(bu, add + int(inv_str_add)))
                u = open('用户名.txt','r')
                h = u.read()
                u.close()
                e1 = open('密码.txt','r')
                h1 = e1.read()
                e1.close()
                if d in h:
                    add = 0
                    s = 1
                    str_add = ''
                    inv_str_add = ''
                    bu = input('请输入密码:')
                    for i in bu:
                        add += ord(i)
                        str_add += str(ord(i))
                    for i in str_add:
                        s += 1
                    for i in range(1, s):
                        inv_str_add += str_add[-i]
                    j = ('{}{}' .format(bu, add + int(inv_str_add)))
                    if j in h1:
                        print('登录成功!')
                        break
                        print(1)
                    else:
                        print('正在为您注册账号···')
                        add = 0
                        s = 1
                        str_add = ''
                        inv_str_add = ''
                        bu = input('请输入您的新用户名:')
                        for i in bu:
                            add += ord(i)
                            str_add += str(ord(i))
                        for i in str_add:
                            s += 1
                        for i in range(1, s):
                            inv_str_add += str_add[-i]
                        a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
                        p = input('请输入您的密码:')
                        i = input('请再次输入您的密码:')
                        if p==i:
                            print('好的,已为您自动登录')
                            e = open('用户名.txt','a')
                            #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                            e.write(a1)
                            e.write('\n')
                            e.close()
                            add = 0
                            s = 1
                            str_add = ''
                            inv_str_add = ''
                            for i in p:
                                add += ord(i)
                                str_add += str(ord(i))
                            for i in str_add:
                                s += 1
                            for i in range(1, s):
                                inv_str_add += str_add[-i]
                            a = ('{}{}' .format(p, add + int(inv_str_add)))
                            e1 = open('密码.txt','a')
                            #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                            e1.write(a)
                            e1.write('\n')
                            e1.close()
                            break
                            print(1)
                        else:
                            print('两次密码不一致,请重新输入')
                else:
                    print('对不起,没有查询到此账号')
                    n = input('您是否需要注册账号,(回答‘是’或‘否’):')
                    if n =='是' :
                        print('对不起,没有查询到此账号')
                        n = input('您是否需要注册账号,(回答‘是’或‘否’):')
                        if n =='是' :
                            print('两次密码不一致,请重新输入')
                            while True:
                                print('正在为您注册账号···')
                                add = 0
                                s = 1
                                str_add = ''
                                inv_str_add = ''
                                bu = input('请输入您的新用户名:')
                                for i in bu:
                                    add += ord(i)
                                    str_add += str(ord(i))
                                for i in str_add:
                                    s += 1
                                for i in range(1, s):
                                    inv_str_add += str_add[-i]
                                a1 = ('{}{}' .format(bu, add + int(inv_str_add)))
                                p = input('请输入您的密码:')
                                i = input('请再次输入您的密码:')
                                if p==i:
                                    print('好的,已为您自动登录')
                                    e = open('用户名.txt','a')
                                    #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                                    e.write(a1)
                                    e.write('\n')
                                    e.close()
                                    add = 0
                                    s = 1
                                    str_add = ''
                                    inv_str_add = ''
                                    for i in p:
                                        add += ord(i)
                                        str_add += str(ord(i))
                                    for i in str_add:
                                        s += 1
                                    for i in range(1, s):
                                        inv_str_add += str_add[-i]
                                    a = ('{}{}' .format(p, add + int(inv_str_add)))
                                    e1 = open('密码.txt','a')
                                    #r = '{'+'\''+y+'\''+':'+'\''+p+'\'''}'
                                    e1.write(a)
                                    e1.write('\n')
                                    e1.close()
                                    break
                break
            print(1)
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片