โดย paoonline » 12/10/2017 11:42 am
ตัวอย่างการสร้างระบบ Login(ล็อคอิน) ด้วยภาษา Python(ไพทอน) เบื้องต้น
โค้ด: เลือกทั้งหมด
#-*- coding: utf8 -*-
print "ยินดีต้อนรับ"
loop = 'true'
while(loop == 'true'): # ทำการ ใช้ while เพื่อ ลูปหา username password ในระบบ
username = raw_input("Enter User: ")
password = raw_input("Enter Pass: ")
if(username == "admin" and password == "1234"):
print 'ล็อกอินสำเร็จ' + username
loop = 'false' #เมื่อลูปเจอ username password ในระบบแล้ว จะเปลี่ยนตัวแปล loop = 'false' เพื่อ ออกจากลูป
loop1 = 'true'
while(loop1 == 'true'): #ทำการใช้ while อีกครั้งเพื่ออกจากระบบ
command = raw_input(username + ">> ")
if(command == "exit"): #ถ้ามีการพิมคำว่า 'exit' ก็จะออกจากระบบ โดย ใช้ break
print 'ออกจากระบบสำเร็จ'
break
else:
print "'" +command+ "' คำสั่งผิด!"
else:
print 'รหัสผ่านผิด'
ตัวอย่างผลลัพธิ์
- Python Knowledge-1.png (78.43 KiB) Viewed 2182 times
สำหรับการการทำระบบ Login บนเว็บด้วย Python แนะนำ ลองดูที่นี่
https://www.mindphp.com/บทเรียนออนไลน์/ ... flask.html
ตัวอย่างการสร้างระบบ Login(ล็อคอิน) ด้วยภาษา Python(ไพทอน) เบื้องต้น
[code]#-*- coding: utf8 -*-
print "ยินดีต้อนรับ"
loop = 'true'
while(loop == 'true'): # ทำการ ใช้ while เพื่อ ลูปหา username password ในระบบ
username = raw_input("Enter User: ")
password = raw_input("Enter Pass: ")
if(username == "admin" and password == "1234"):
print 'ล็อกอินสำเร็จ' + username
loop = 'false' #เมื่อลูปเจอ username password ในระบบแล้ว จะเปลี่ยนตัวแปล loop = 'false' เพื่อ ออกจากลูป
loop1 = 'true'
while(loop1 == 'true'): #ทำการใช้ while อีกครั้งเพื่ออกจากระบบ
command = raw_input(username + ">> ")
if(command == "exit"): #ถ้ามีการพิมคำว่า 'exit' ก็จะออกจากระบบ โดย ใช้ break
print 'ออกจากระบบสำเร็จ'
break
else:
print "'" +command+ "' คำสั่งผิด!"
else:
print 'รหัสผ่านผิด'[/code]
ตัวอย่างผลลัพธิ์
[attachment=0]Python Knowledge-1.png[/attachment]
สำหรับการการทำระบบ Login บนเว็บด้วย Python แนะนำ ลองดูที่นี่
https://www.mindphp.com/บทเรียนออนไลน์/python-framework-flask.html