首页 > 代码库 > 用户的删除,添加,修改密码,显示时间戳

用户的删除,添加,修改密码,显示时间戳

#!/usr/bin/env python

#coding=utf-8

import time

dic = {"root":["westos",1020]}

def menu():

while True:

    print ‘‘‘

    (D)elete user

    (S)how user

    (E)xit

    (A)dd user

    (L)ogin

    ‘‘‘

choice = raw_input("input your choice:")

if choice =="L":

    login()

elif choice =="D":

    delete()

elif choice =="A":

    add()

elif choice =="S":

    show()

elif choice =="E":

    exit(0)

else:

    print "error input"

def delete():

username =raw_input("input username:")

        if  dic.has_key(username):

            passwd = raw_input("input passwd:")

            if passwd == dic[username][0]:

                print "delete user success"

            else:

                print "delete failed"

        else:

            print "no this user"

def show():

username =raw_input("input username:")

if dic.has_key(username):

    print dic

else:

    s=raw_input("no this user,are you want to add user:(yes/no)")

    if s == "yes":

        add()

        print dic

    else:

        print "input username error"

def login():

username =raw_input("input username:")

        if dic.has_key(username):

            passwd =raw_input("input passwd:")

                if passwd ==dic[username][0]:

                print "login success,welcome back %s" %username

                      now=time.time()

                if now-dic.get(username)[1] <= 14400:

                     print "you have logged in %s" %(time.ctime(dic[username][1]))

                else:

                     print "you loggin as %s:"%(time.ctime(dic[username][1]))

            else:

                print "passwd error"

        else:

            string = raw_input("are you sure to add user:(yes/no)")

            if string == "yes":

                add()

            else:

                login()

--------------------------------------------------------------

#def login():

#for i in range(0,3):

#username = raw_input("Please input username:")

#if dic.has_key(username):

#passwd =raw_input("input passwd:")

#               if passwd ==dic[username][0]:

#                  print "login success,welcome back %s" %username

#if time.time()-dic[username][1]>14400:

#                             print "Last login:%s"%(time.ctime(dic[username][1]))

#                        else :

#                                print "You already login %s within 4 hours"%(time.ctime(dic[username][1]))

#                       break

#else:

#                        print "ERROR:username is not exist or password error"

#                        print "you have %d chance"%(2-i)

------------------------------------------------------------------

def add():

username =raw_input("input username:")

passwd =raw_input("input passwd:")

print " add username success"

dic.update({username:[passwd,]})

menu()


本文出自 “12444546” 博客,谢绝转载!

用户的删除,添加,修改密码,显示时间戳