A simple program that I wrote that will allow the user to log in the system using Ruby programming language and MySQL. I am a beginner in Ruby programming and I have found hard to find a code on the Internet about Ruby and MySQL Login System to I wrote one. I hope you will find my work useful.
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.rb
###################################################
# Author : Mr. Jake Rodriguez Pomperada,MAED-IT
# Tools : Ruby Version 2.6.3 and Notepad++
# Date : May 15, 2019 Wednesday
# Location : Bacolod City,Negros Occidental
# Website : http://www,jakerpomperada.com
# Email : jakerpomperada@gmail.com
###################################################
# login - database
# users - table
#
# id - primary key
# username - varchar(100)
# password - varchar(100)
require 'mysql'
class MysqlDatabase
def initialize(server,database,username,password)
@svr = server
@db = database
@usr = username
@pwd = password
end
def login_check(uname,pword)
mysql = Mysql.connect(@svr, @usr, @pwd, @db)
stmt = mysql.prepare('SELECT username,password FROM users WHERE username = ? AND password = ?')
stmt.execute uname,pword
n_rows = stmt.num_rows
if n_rows == 1
print "\n\n"
print "\tWelcome to the System #{uname.upcase}."
print "\n\n"
else
print "\n\n"
print "\tAccess Denied. Try Again Please."
print "\n\n"
mysql.close()
end
end
end
print "\n\n"
print "\tLOGIN SYSTEM USING RUBY AND MYSQL\n\n"
print "\tAUTHOR: JAKE RODRIGUEZ POMPERADA"
print "\n\n"
print "\tEnter Username : "
username2 = gets.chomp
print "\tEnter Password : "
password2 = gets.chomp
db = MysqlDatabase.new('127.0.0.1','login','root','')
db.login_check(username2.downcase,password2.downcase)
# End of Code
users.sql
-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 15, 2019 at 06:09 AM
-- Server version: 10.1.38-MariaDB
-- PHP Version: 7.1.28
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: `login`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `username`, `password`) VALUES
(1, '123', '123'),
(2, 'admin', 'admin'),
(3, 'jake', 'jake'),
(4, 'root', 'root'),
(5, 'abc', 'abc'),
(6, 'demo', 'demo');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
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