Friday, March 8, 2019

Login and Registration in Python and MySQL

Here is a program that we wrote together with my best friend Rolly M. Moises a login and registration created using Python programming language and MySQL as our backend database. We wrote this code for our upcoming book on Python programming.

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


# login_registration.py
# Rollyn M. Moises and Jake R. Pomperada
# March 8, 2019   Friday
# Bacolod City, Negros Occidental

import pymysql
import subprocess as sp
import getpass


class Login:

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

    def check_user(self, username, pwd):
        try:
            with self.connection.cursor() as cursor:
                sql = "SELECT * FROM users WHERE username = %s and password = %s"
                try:
                    rows = cursor.execute(sql, (username, pwd,))
                    if rows > 0:
                        record = cursor.fetchone()
                        print()
                        print("\tHello %s %s" % (record[3], record[4]),'.')
                        print()
                        print("\tWelcome to the System.")
                    else:
                        print("\tInvalid Username and/or Password. Try again.")
                except:
                    print("\tUnable to fetch records")

            self.connection.commit()
        except:
            self.connection.close()

    def login_screen(self):
        print()
        print("\tLOGIN SECURITY PAGE");
        print()
        user = input("\tEnter Username : ")
        password = getpass.getpass(prompt='\tEnter Password :')
        self.check_user(user, password)

    def logout(self):
        print("\n")
        print("\t\t\tTHANK YOU FOR USING THIS SOFTWARE.")
        print()
        print("\tCopyright 2019.  Product of Bacolod City, Negros Occidental Philippines.")
        print()
        self.connection.close()

    def register_user(self, username, password, firstname, lastname):
        try:
            with self.connection.cursor() as cursor:
                sql = "INSERT INTO users (`username`, `password`,`firstname`,`lastname`) VALUES (%s, %s,%s,%s)"
                try:
                    cursor.execute(sql, (username, password, firstname, lastname))
                    print()
                    print("\tRegistration Successfully Saved in the Database.")
                except:
                    print()
                    print("\tUnable to Register User.")
            self.connection.commit()
        except:
            self.connection.close()

    def register(self):
        print()
        print("\tLOGIN REGISTRATION PAGE");
        print()
        user = input("\tEnter Username : ")
        password = getpass.getpass(prompt='\tEnter Password : ')
        confirm_password = getpass.getpass(prompt='\tConfirm Password : ')
        print()
        first_name = input("\tEnter Firstname : ")
        last_name = input("\tEnter Lastname   : ")
        print()
        if password != confirm_password:
            print("\tPassword does not match. Try Again.")
        else:
            self.register_user(user, password, first_name.upper(),last_name.upper())


class Menu:

    def logout(self):
        self.login.logout()

    def selection(self):
        ch = "0"
        self.login = Login()
        while ch != "3":
            tmp = sp.call('cls', shell=True)
            print()
            print("\t\t    LOGIN AND REGISTRATION SYSTEM");
            print("\t\t\t     CREATED BY");
            print("\t\tROLLYN  M. MOISES AND JAKE R. POMPERADA")
            print()
            print("\t[1] Login Registered User")
            print("\t[2] Register New User")
            print("\t[3] Exit Program")
            print()
            ch = input("\tSelect option : ")
            menu_selection = {
                "1": self.login.login_screen,
                "2": self.login.register,
                "3": self.logout,
            }
            func = menu_selection.get(ch)
            if func is not None:
                func()
            else:
                print("\tInvalid option selected")
            print()
            input("\tPRESS ENTER KEY TO CONTINUE.")
menu = Menu()
menu.selection()


school_management.sql

-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Mar 08, 2019 at 04:32 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
(8, 'Jake Rodriguez Pomperada', 'Bachelor 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,
  `firstname` varchar(100) DEFAULT NULL,
  `lastname` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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

INSERT INTO `users` (`id`, `username`, `password`, `firstname`, `lastname`) VALUES
(4, 'admin', 'admin', 'JAKE', 'POMPERADA'),
(5, '123', '123', 'ROLLYN', 'MOISES');

--
-- 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=9;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
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 */;


DOWNLOAD SOURCE CODE HERE


Wednesday, March 6, 2019

Accept and Displays Values Using Lists in Python

Write a program using a list that will accept ten integer values and then the program will display all the ten integer values given by the user on the screen.

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


Program Listing

# list.py
# Rollyn M. Moises and Jake R. Pomperada
# March 1, 2019   Friday
# Bacolod City, Negros Occidental

memo=[]
print();
print("\t Accept and Displays Values Using Lists");
print();
for i in range (10):
    x=int(input("\t Give value in item no. {0} : ".format(i+1)))
    memo.insert(i,x)
    i+=1;

print();
print("\t The List of Values")
print();
print("\t",memo);
print();
print("\t END OF PROGRAM");



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 */;



Menu Driven CRUD in Python and MySQL

A simple menu driven crud program that we wrote together with my mentor in programming and best friend Rollyn M. Moises for our upcoming book in Python programming.

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# CRUD 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 subprocess as sp

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

def add_record():
   print();
   print("ADD STUDENT RECORD")
   print();
   name = input("Enter Student Name     : ")
   course = input("Enter Student Course   : ")
   print();
   try:
      with connection.cursor() as cursor:
         sql = "INSERT INTO student (`name`, `course`) VALUES (%s, %s)"         try:
            cursor.execute(sql, (name, course))
            print("Student added successfully")
         except:
            print("Unable to save student record")
      connection.commit()
   finally:
      print("") #connection.close()
def select_records():
   
   try:
      with connection.cursor() as cursor:
         sql = "SELECT `id`, `name`, `course` FROM student"         try:
            cursor.execute(sql)
            result = cursor.fetchall()
            print();
            print("VIEW STUDENT RECORDS")
            print();
            print("ID\t\t NAME\t\t\t\t\t\t\t\tCOURSE")
            print("---------------------------------------------------------------------------")
            for row in result:
               print(str(row[0]) + "\t\t" + row[1] + "\t\t\t" + row[2])
 
         except:
            print("Unable to fetch records")
 
      connection.commit()
   finally:
      print("") #connection.close()
def delete_input():
   print();
   print("DELETE STUDENT RECORD")
   print();
   id = input("Enter Student ID         : ")
   print();
   delete_record(id)

def delete_record(id):

   try:
      with connection.cursor() as cursor:
         sql = "DELETE FROM student WHERE id = %s"         try:
            cursor.execute(sql, (id,))
            print("Successfully Deleted the Record...")
         except:
            print("Unable to delete record")
 
      connection.commit()
   finally:
      print("") #connection.close()

def update_input():
   print()
   print("UPDATE STUDENT RECORD")
   print();
   id = input("Enter Student ID         : ")
   name = input("Enter Student Name       : ")
   course = input("Enter Student Course     : ")
   print();
   update_record(id, name, course)

def update_record(id, name, course):

   try:
      with connection.cursor() as cursor:
         sql = "UPDATE student SET `name`=%s, `course`=%s WHERE `id` = %s"         try:
            cursor.execute(sql, (name, course, id))
            print("Successfully Updated the Record...")
         except:
            print("Unable to update record")
 
      connection.commit()
   finally:
      print("") #connection.close()
def exit_app():
   print();
   print("\tThank you for using this software.");
   print();
   connection.close()

def menu_option():
   ch = "0"   while ch != "5":
      tmp = sp.call('cls',shell=True)
      print();
      print("===== STUDENT RECORD SYSTEM =====");
      print();
      print("1. Add Student Record")
      print("2. Update Student Record")
      print("3. Show Student List Record")
      print("4. Delete a student Record")
      print("5. Quit Program ")
      print();
      ch = input("Select option : ")
      menu_selection = {
         "1": add_record,
         "2": update_input,
         "3": select_records,
         "4": delete_input,
         "5": exit_app
      }  
      func = menu_selection.get(ch)
      if func is not None:
         func()
      else:
         print("Invalid option selected")
      print();
      input('PRESS THE ENTER KEY TO CONTINUE ')

menu_option()


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 */;





Monday, March 4, 2019

Example No. 2 using Two Dimensional List in Python

To append a new list of values into a two-dimensional list in Python example.

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

# example2.py
# Jake R. Pomperada
# March 4, 2019   Monday
# Bacolod City, Negros Occidental
print();
print("\tExample No. 2 using Two Dimensional List");
print();
list_example = [[1,2,3], [4, 5, 6],[7,8,9,10]]
list_example.append([11,12,13,14,15])
print("\tDisplay Result")
print();
print("\t",list_example);
print();
print("\tEND OF PROGRAM")



Odd and Even Numbers using Two Dimensional List in Python

Write a program that will ask the user how many values to be processed. The program also will ask the user to give integer values using two-dimensional list and check which of the given number is odd or even numbers being provided by the user and display the result on the screen.

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



# odd_even.py
# Rollyn M. Moises and Jake R. Pomperada
# March 4, 2019   Monday
# Bacolod City, Negros Occidental
print();
print("\tOdd and Even Numbers using Two Dimensional List");
print();
num = int(input('\tHow many numbers: '))
print();
accept = []
for a in range(0,num):   #row
    accept.append([])
for b in range(0,num) : # row
    for c in range(0,1) : # column
        accept[b].append(c);
        accept[b][c]=0;

for b in range(0,num) : # row
    for c in range(0,1) : # column
         accept[b][c]=int(input("\tGive value in item no. {0} : ".format(b+1)));

print();
print("\tDisplay Result")
print();
print("\tList of EVEN Numbers");
print();
for i in range(len(accept)):
    for j in range(len(accept[i])):
        if accept[i][j] % 2 == 0:
         print("\t",accept[i][j], end=" ")
print("\n");
print("\t List of ODD Numbers");
print();
for i in range(len(accept)):
    for j in range(len(accept[i])):
        if accept[i][j] % 2 != 0:
         print("\t",accept[i][j], end=" ")
print("\n");
print("\tEND OF PROGRAM")