python simple simulation blog park system


# With a code to simulate blog park system
#
# Project Analysis:
# 1. First, the program starts, displays the following contents for users to choose:
#
# 1. Go to
# 2. Please register
# 3. Go to page article
# 4. Enter comments page
# 5 into the diary page
# 6. Go to collection page
# 7. cancellation account
# 8. quit the whole program
# 2. We must realize the function:
#
# 1. Registration functional requirements:
. # A user name and password to be recorded in the file.
. # B User Requirements: You can not have special characters and ensure that the user name is unique.
. # C password requirements: a length between 6 to 14 characters.
#
# 2. Log functional requirements:
. # A user enters a username and password login authentication.
. # B after a successful login can be accessed 3--7 options, visit 3:00 If you do not log on or log unsuccessful --7 option does not allow access, the user is prompted to log in!
# C login has not yet succeeded more than three times, then exit. the entire program.
#
# 3. Go to the article page Requirements:
# prompt welcome xx enter the article page. (xx is the user name currently logged in)
#
# 4. Enter comments page Requirements:
#
# prompt Welcome page xx Enter comments
#
# 5. Requirements to enter the diary page:
Tip # xx welcomed into the diary page.
#
# 6. Go to page collection requirements:
# prompt Welcome page xx into the collection.
#
# 7. cancellation account requirements:
# not quit the whole program, but the state has logged into the unregistered status (need to login again when the visit from 3 to 7 options)
#
# 8. quit the whole program requirements:
# is end of the process
Import hashlib

login_dic = {
'Status': False
}

S1 = "" # global variable
DEF warpper (FUNC):
DEF Inner (* args, ** kwargs):
IF login_dic [ 'Status'] == True:
RET FUNC = (* args, ** kwargs)
return RET
the else:

the Login (* args, ** kwargs)
FUNC (* args, ** kwargs)

return Inner

DEF yonghuming (): # username validation function
while True:
the INPUT = username ( "username:")
for i in username:
IF not i.isalnum ():
Print ( "No")
BREAK
the else:
return username

DEF mima (): # password verification function
the while True:
pwd = the INPUT ( " pwd: ")
for I in pwd:
IF. 6 <= len (pwd) <= 14:
Print (" OK ")
return pwd
the else:
Print (" re-enter the password ")


DEF zhuce (* args, ** kwargs):
s2 = yonghuming () # username call authentication
s3 = mima () # call password authentication
md5 = hashlib.md5 () # initial encryption template
md5.update (s3.encode ( 'utf-8 '))
m = md5.hexdigest()
with open('flag', 'a+', encoding="utf-8") as f:
f.seek(0)
f.write(f"{s2}:{m}\n")
print("注册成功")

def login(*args, **kwargs):
for i in range(3):
username1 = input("username:")
pwd1 = input("pwd:")
md5 = hashlib.md5() # 初始化加密模板
md5.update(pwd1.encode('utf-8'))
m1 = md5.hexdigest()
with open('flag', 'r', encoding='utf-8') as f1:
for i in f1:
username, pwd = i.strip().split(":")
if username == username1 and m1 == pwd:
login_dic['status'] = True
Print ( "Login successful")
S1 Global
S1 = # username modify global variables
return S1
the else:
Print ( "username password error")
the else:
Print ( "slightly wrong 3 times !!")

@wrapper
DEF blog_wz (S1):
IF login_dic [ 'Status' ]:
Print (f "Welcome {s1} enter the article page")
@wrapper
DEF blog_pl (s1):
IF login_dic [ 'Status']:
Print (f "Welcome {s1} enter comments page")


@wrapper
DEF blog_rz (s1 ):
IF login_dic [ 'Status']:
Print (F "Welcome {s1} log into the page")


@wrapper
DEF blog_sc (S1):
IF login_dic [ 'Status']:
Print (F "to enter collection {s1} Welcome page ")


@wrapper
def blog_zx(s1):
IF login_dic [ 'Status']:
login_dic [ 'Status'] = False
Print ( "write-off account")


msg = "" "
1, register
2, log
3, enter the article page
4, enter comments page
5, to the Log page
6 enter the collection page
7, close the account
8. quit
"" "
DIC1 = {
'. 1': zhuce,
'2': Login,
'. 3': blog_wz,
'. 4': blog_pl,
'. 5': blog_rz,
'. 6' : blog_sc,
'. 7': blog_zx,
'. 8': Exit
}
DEF RUN ():
the while True:
, my_str = INPUT (MSG)
IF, my_str in DIC1:
IF, my_str == '. 8':
return
dic1[my_str](s1)
else:
print ( "input error number")



IF the __name__ == '__main__':
RUN ()

Guess you like

Origin www.cnblogs.com/niucunguo/p/12040619.html