Blogger Information
Blog 75
fans 0
comment 0
visits 54639
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小猿圈python之学习登录验证
聆听的博客
Original
902 people have browsed it

相信大家对登录验证很熟悉吧,几乎每个网站都有这个功能,这篇文章小猿圈加加详细说下登录验证的逻辑,正在学习的朋友可以当做一个练习题。

实例

#!/usr/bin/env python

#-*- coding=utf-8 -*-

#导入模块

import os

import sys

#设置账户密码

user_name = ['root', 'sj', 'None']

user_passwd = ['123qwe', '123123', 'None']

file_list = '/home/jj/py/file/user_db.txt'

#--------登陆验证------

def user_login ():

  i = 0

  def passwd_login ():

    while True:

      global NAME_INPUT

      NAME_INPUT = raw_input("请输入您的用户名:").strip()

      if len(NAME_INPUT) == 0:

        print "用户名不能为空!"

        continue

      else:

        break

    return

  passwd_login()

  while True:

    if i < 3:

      passwd_input = raw_input("请输入您的密码:")

      if len(passwd_input) == 0:

        print "密码不能为空!"

        continue

      elif NAME_INPUT not in user_name:

        print("您输入的密码有误,请您重新输入!")

        i += 1

        continue

      else:

        if passwd_input == user_passwd[user_name.index(NAME_INPUT)]:

          print("您好%s,欢迎登陆员工信息查询系统!") % NAME_INPUT

          break

        else:

          print("密码有误,请重新输入您的密码")

          i += 1

          continue

        break

      break

    else:

      print "您的密码输错3次请您重新核对账号和密码!"

      i = 0

      passwd_login()

      continue

user_login()

print("OK")

OK,这个功能就是这样的逻辑,看起来大部分都是用的条件语句,没毛病,懂得这个逻辑就会很快写出来,感觉不错的朋友,可以做做其他功能,其实一个页面的功能感觉很难,但是就是根据平时学的简单的语法构成的,小猿圈网有其他的功能练习,跟着练习一下。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!