Wednesday, March 6, 2019

Login Application in Python and MySQL

In this article, we would like to share with you guys a login program written by me and my best friend Rolly M. Moises to log in using Python and MySQL. The code is very easy to use and understand.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting.

work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com




Sample Program Output


Program Listing

# Rollyn M. Moises and Jake R. Pomperada# Login Application in Python and MySQL# Tools            : PyCharm Community Edition 2018.3# Date             : March 6, 2019  Wednesday# Place of Origin  : Bacolod City, Negros Occidental Philippines# Website          : http://www.jakerpomperada.com
import pymysql
import getpass

connection = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    password='',
    db='school_management',
)

def login():
 print("==== LOGIN SECURITY SYSTEM =====");
 print();
 user = input("Enter Username : ")
 password = getpass.getpass(prompt='Enter Password :')
 print("\n");
 query_db(user, password)


def query_db(username, pwd):

   try:
      with connection.cursor() as cursor:
         sql = "SELECT * FROM users WHERE username = %s and password = %s"         try:
            rows = cursor.execute(sql, (username, pwd,))
            if rows > 0:
             print("Login successful in the system.")

            else:
               print();
               print("Invalid username and/or password.")
               print();
               print();
               login()
         except:
            print("Unable to fetch records")
 
      connection.commit()
   finally:
      connection.close()
   print("\n");
   input("PRESS ENTER KEY TO CONTINUE")

print()
login()


school_management.sql

-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Mar 06, 2019 at 02:17 AM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.3.0

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `school_management`
--

-- --------------------------------------------------------

--
-- Table structure for table `student`
--

CREATE TABLE `student` (
  `id` int(11) NOT NULL,
  `name` varchar(100) DEFAULT NULL,
  `course` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `student`
--

INSERT INTO `student` (`id`, `name`, `course`) VALUES
(2, 'Jake Pomperada', 'Master in Information Technology'),
(3, 'Rollyn M. Moises', 'Master of Science in Computer Science');

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(100) DEFAULT NULL,
  `password` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`) VALUES
(1, '123', '123'),
(2, 'admin', 'admin');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `student`
--
ALTER TABLE `student`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `student`
--
ALTER TABLE `student`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;



No comments:

Post a Comment