Python implements registration and login system

不言
Release: 2018-04-24 16:20:19
Original
7987 people have browsed it

This article mainly introduces in detail the Python3 bank account login system suitable for beginners to learn. It has certain reference value. Interested friends can refer to it.

The form is mainly responsible for the web page Data collection function. A form has three basic components: Form tag: This contains the URL of the CGI program used to process the form data and the method for submitting the data to the server. Form fields: including text boxes, password boxes, hidden fields, multi-line text boxes, check boxes, radio button boxes, drop-down selection boxes and file upload boxes, etc. Form buttons: include submit buttons, reset buttons and general buttons; used to transfer data to CGI scripts on the server or cancel input. Form buttons can also be used to control other processing tasks with defined processing scripts. In HTML, enter a URL in the address bar and open it. This sends a get request. If you want to use a POST request, you need to use a form.

The form in HTML is declared by the form tag. For example:

<form action="login" method="post"> 
 <label>username:</label> 
 <input type="text" name="username"><br /> 
 <label>password:</label> 
 <input type="password" name="password"><br /> 
 <input type="submit" name="submit"> 
<form>
Copy after login

In the above code, it is included by the form tag The part is the content of the form, and focus on the input part. There are three inputs in this form, one is of text type, representing ordinary text input, one is of password type, representing password input, and one is of submit type. It is a submit button; the form tag defines two attributes, one is action, which represents the path to submit the form, and the other is method, which represents the method for submitting the form. The default is GET. Next, let’s explain the specific process of the above example in detail. When the user clicks the submit button, the browser sends a POST request to the action path. The content of the request is as follows

data = { 
 &#39;username&#39;:&#39;XXXXXXXX&#39;, 
 &#39;password&#39;:&#39;XXXXXXXX&#39; 
}
Copy after login

# This is to use the name of the INPUT in all except Submit as the key value, and the actual data filled in as the value of the value packet, and a post request is sent. If the method is changed to get, then a GET request will be sent. Next, the request data received by the server is the same as the data sent from the client program. The next step is to perform corresponding processing based on the data sent and then return.

With the above knowledge in hand, we will start to make a simple registration and login system. The registration and login system we built has a registration function and a login function. After registration, the server stores the registration information locally and verifies whether the registration message is correct when logging in. There are some templates in web.py that already have some support. The specific code is as follows:

# -*- coding: cp936 -*- 
import web 
import os 
 
urls = ( 
 &#39;/&#39;, &#39;hello&#39;, 
 &#39;/login&#39;, &#39;login&#39;, 
 &#39;/regist&#39;, &#39;regist&#39; 
) 
app = web.application(urls, globals()) 
class hello: 
 def __init__(self): 
  self.render = web.template.render(&#39;templates/&#39;) 
 def GET(self): 
  return self.render.form() 
 
 
class login: 
 def POST(self): 
  para = web.input() 
  username = para[&#39;username&#39;] 
  password = para[&#39;password&#39;] 
 
  #TODO:... 
  #if authenticate(username,password): 
   #return render.hello(username) 
  return &#39;hello world&#39; 
 
class regist: 
 def GET(self): 
  return &#39;hello world&#39; 
  #return self.render.form() 
 def POST(self): 
  para = web.input() 
  username = para[&#39;username&#39;] 
  password = para[&#39;password&#39;] 
 
  #TODO:... 
  return &#39;hello world&#39; 
 
if __name__ == &#39;__main__&#39;: 
 app.run()
Copy after login

The running effect is as follows: I want to make it more beautiful by myself , you can find some relevant information yourself! What this implements is entering a password and returning a value. You can see that there is no local saving, yes, this is the pit left for you in TODO! Then just remove the comments in the login class above for password matching or something!


##Python realizes automatic login to campus network


The above is the detailed content of Python implements registration and login system. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template