Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make simple login in python

username = input(' enter your username: ')
if username == 'Put Your Username Here':#change this
   print("checking username")
   time.sleep(0.5)
   print("username is right") 
   password = input(' type your password: ')
   if password == 'Put Your Password Here':#change this
    time.sleep(0.5) 
   else:
    exit()
else:
 exit()    
Comment

python - login

// Paste then into views.py inside the APP folder

from django.shortcuts import render, redirect
from .models import Team
from cars.models import Car
from django.contrib import messages, auth
from django.contrib.auth.models import User


def login(request):
    if request.method == 'POST':

        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username, password=password)

        if user is not None:
            auth.login(request, user)
            messages.success(request, 'You are now logged in.')
            return redirect('dashboard')
        else:
            messages.error(request, 'Invalid login credentials')
            return redirect('login')

    return render(request, 'pages/login.html')



// inside login.html 
// Note: The ( type="") and ( name="" ) must in small letter 
// Must be the same in database 

{% include 'includes/messages.html' %}
<form action="{% url 'login'%}" method="POST">
  {% csrf_token %}
    <div class="form-group form-box">
        <input type="text" name="username" class="input-text" placeholder="Username" required>
        <i class="flaticon-mail"></i>
    </div>
    <div class="form-group form-box">
        <input type="password" name="password" class="input-text" placeholder="Password" required>
        <i class="flaticon-lock"></i>
    </div>
    <div class="form-group mb-0 clearfix">
        <button type="submit" class="btn-md btn-theme float-left">Login</button>
    </div>
    <div class="extra-login clearfix">
        <span>Or Login With</span>
    </div>
    <div class="clearfix"></div>
    <ul class="social-list">
        <li><a href="#" class="facebook-bg"><i class="fa fa-facebook facebook-i"></i><span>Facebook</span></a></li>
        <li><a href="#" class="google-bg"><i class="fa fa-google google-i"></i><span>Google</span></a></li>
    </ul>
</form>
Comment

login python code

username = input(' enter your username: ')
if username == 'Put Your Username Here':#change this
   print("checking username")
   time.sleep(0.5)
   print("username is right") 
   password = input(' type your password: ')
   if password == 'Put Your Password Here':#change this
    time.sleep(0.5) 
   else:
    exit()
else:
 exit()    
Comment

PREVIOUS NEXT
Code Example
Python :: python sort array by key 
Python :: python / vs // 
Python :: change value in dataframe 
Python :: linux python virtual environment 
Python :: python check if key exist in dict 
Python :: pygame python 
Python :: how to update a python package 
Python :: python oops 
Python :: correlation matrix in python 
Python :: flask documentation 
Python :: pyplot.plot 
Python :: how to print from a python list 
Python :: flask app.route 
Python :: program to count the number of occurrences of a elementes in a list python 
Python :: numpy split 
Python :: python ascii art 
Python :: convert int to hexadecimal 
Python :: filter json python 
Python :: random.choices without repetition 
Python :: bitwise operation in python 
Python :: how to find a key in a dictionary python 
Python :: Pass a variable to dplyr "rename" to change columnname 
Python :: python elif 
Python :: text detection from image using opencv python 
Python :: python simplify fraction 
Python :: NEW CALENDAR MODULE 
Python :: flatten dict with lists as entries 
Python :: turn list of arrays into array 
Python :: how to add two strings in python 
Python :: how to check if string ends with specific characters in python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =