Tuesday, November 2, 2021

Login Security System in AngularJS, PHP, and MySQL

 

We will create a Login Security System using AngularJS, PHP, and MySQL that will provide security features in your web, or mobile applications.

nd application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at 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.










Program Listing

angular_login.sql

 

-- phpMyAdmin SQL Dump

-- version 5.0.3

-- https://www.phpmyadmin.net/

--

-- Host: 127.0.0.1

-- Generation Time: Oct 23, 2021 at 05:06 AM

-- Server version: 10.4.14-MariaDB

-- PHP Version: 7.4.11

 

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

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: `angular_login`

--

 

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

 

--

-- Table structure for table `members`

--

 

CREATE TABLE `members` (

  `memid` int(11) NOT NULL,

  `username` varchar(50) NOT NULL,

  `password` varchar(50) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

 

--

-- Dumping data for table `members`

--

 

INSERT INTO `members` (`memid`, `username`, `password`) VALUES

(1, 'admin', 'admin'),

(2, '123', '123'),

(3, 'jake', 'jake'),

(4, 'jacob', 'jacob'),

(5, 'iya', 'iya'),

(6, 'allie', 'allie');

 

--

-- Indexes for dumped tables

--

 

--

-- Indexes for table `members`

--

ALTER TABLE `members`

  ADD PRIMARY KEY (`memid`);

 

--

-- AUTO_INCREMENT for dumped tables

--

 

--

-- AUTO_INCREMENT for table `members`

--

ALTER TABLE `members`

  MODIFY `memid` 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 */;     

 

 

Controllers Folder

 

loginCtrl.js

 

'use strict';

 

app.controller('loginCtrl', function($scope, loginService){

            $scope.errorLogin = false;

            $scope.successLogin = false;

 

            $scope.login = function(user){

                        loginService.login(user, $scope);

            }

 

            $scope.clearMsg = function(){

                        $scope.errorLogin = false;

                        $scope.successLogin = false;

            }

});        

 

 

Services Folder

 

loginService.js

 

'use strict';

 

app.factory('loginService', function($http) {

            return {

                        login: function(user, $scope) {

                                    var validate = $http.post('login.php', user);

                                    validate.then(function(response) {

                                                if (response.data.error == true) {

                                                            $scope.successLogin = false;

                                                            $scope.errorLogin = true;

                                                            $scope.errorMsg = response.data.message;

                                                } else {

                                                            window.location.href = 'home.html';

                                                }

                                    });

                        }

            }

});

 

 

 

angular.js

 

var app = angular.module('app', ['ngRoute']);

 

app.config(function($routeProvider){

            $routeProvider

            .when('/', {

                        templateUrl: 'login.html',

                        controller: 'loginCtrl'

            })

            .when('/home', {

                        templateUrl: 'home.html'

            })

            .otherwise({

                        redirectTo: '/'

            });

});

 

 

login.php

 

<?php

           

$conn = new mysqli("localhost", "root", "", "angular_login");

 

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}

 

$out = array('error' => false);

 

$user = json_decode(file_get_contents('php://input'));

 

$username = $user->username;

$password = $user->password;

 

$sql = "SELECT * FROM members WHERE username='$username' AND password='$password'";

$query = $conn->query($sql);

 

if($query->num_rows>0){

            $out['message'] = 'Login Successful';

}

else{

            $out['error'] = true;

            $out['message'] = 'Invalid Login';

}

 

echo json_encode($out);

 

?>

 

style.css

 

@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');

 

:root {

            --black: #343a40;

            --gray: #6c757d;

            --white: #ffffff;

}

 

body {

            font-family: 'Roboto', sans-serif;

            min-height: 100vh;

            height: 100%;

}

 

.section {

            min-height: 100vh;

    display: flex;

    justify-content: center;

            align-items: center;

}

 

.bg-dark {

    background-color: var(--black);

}

 

h1 {

            margin: 20px 0;

}

 

.title {

    color: var(--white);

}

 

.welcome {

            margin-top: 100px;

    color: var(--black);

}

 

.welcome h1:nth-of-type(2) {

            margin-top: 80px;

}

 

.titlehr {

            border-top: 3px double #8c8b8b;

            width: 100%;

            max-width: 300px;

}

 

form {

    width: 400px;

            color: var(--black);

}

 

h1,

input,

.btn {

    margin-bottom: 30px;

}

 

.btn-dark {

            color: var(--white);

    background-color: var(--black);

    border-color: var(--black);

}

 

.btn-dark:hover {

    color: var(--white);

    background-color: #23272b;

    border-color: #23272b;

}

 

 

 

index.html

 

<!DOCTYPE html>

<html ng-app="app">

<head>

    <title>AngularJS Login with PHP/MySQLi</title>

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <link href="styles.css" rel="stylesheet">

</head>

<body>

<div class="container-fluid">

    <div class="row">

        <div class="col-lg-5 section bg-dark">

            <div class="title text-center">

                <hr class="titlehr">

                <h1 class="text-white">

                    AngularJS Login<br>

                     with PHP/MySQLi

                    <br>

                </h1>

 

                <h4 class="text-uppercase">Created By:</h3>

                <h4>Prof. Jake Rodriguez Pomperada, MAED-IT, MIT</h4>

                <hr class="titlehr">

            </div>

        </div>

        <div class="col-lg-7 section">

            <div ng-view></div>

        </div>

    </div>

</div>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.min.js"></script>

<script src="js/angular.js"></script>

<script src="js/controllers/loginCtrl.js"></script>

<script src="js/services/loginService.js"></script>

</body>

</html>

 

login.html

 

<form role="form" name="logform" autocomplete="off">

    <h1 class="text-center">

        <span class="glyphicon glyphicon-lock"></span> Login

    </h1>

    <fieldset>

        <div class="form-group">

            <label for="txtUser">Username</label>

            <input class="form-control" id="txtUser" type="text" autofocus ng-model="user.username" placeholder="Enter your username here" required>

        </div>

        <div class="form-group">

            <label for="txtPass">Password</label>

            <input class="form-control" id="txtPass" type="password" ng-model="user.password" placeholder="Enter your password here" required>

        </div>

        <button type="submit" id="loginbutton" class="btn btn-dark btn-block" ng-disabled="logform.$invalid" ng-click="login(user)">

            <span class="glyphicon glyphicon-log-in"></span> <span id="logtext">Login</span>

        </button>

    </fieldset>

</form>

 

<div class="alert alert-danger text-center" ng-show="errorLogin">

    <button type="button" class="close" ng-click="clearMsg()"><span aria-hidden="true">&times;</span></button>

    {{ errorMsg }}

</div>

 

home.html

 

<!DOCTYPE html>

<html ng-app="app">

<head>

    <title>AngularJS Login with PHP/MySQLi</title>

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <link href="styles.css" rel="stylesheet">

</head>

<body>

    <div class="container-fluid">

        <div class="row">

            <div class="col-12">

                <div class="title text-center welcome">

                    <hr class="titlehr">

                    <h1 class="text-uppercase">

                        AngularJS Login<br>

                        <small> with PHP/MySQLi</small>

                        <br>

                    </h1>

                    <h4 class="text-uppercase">Created By:</h3>

                    <h4>Prof. Jake Rodriguez Pomperada, MAED-IT, MIT</h4>

                    <hr class="titlehr">

 

                    <h1>Welcome to the homepage!</h1>

                    <a href="index.html">Back to login page</a>

                </div>

            </div>

        </div>

    </div>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.min.js"></script>

<script src="js/angular.js"></script>

<script src="js/controllers/loginCtrl.js"></script>

<script src="js/services/loginService.js"></script>

</body>

</html>

 DOWNLOAD THE COMPLETE SOURCE CODE HERE



Basic Arithmetic in C#

Basic Arithmetic in C#

 

Machine Problem

Write a C# sharp program that will ask two integers,and display it's sum , difference , product ,quotient and remainders .

  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 at 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.







Program Listing


Program.cs


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


/* Prof. Jake Rodriguez Pomperada, MAED-IT, MIT

 * www.jakerpomperada.com and www.jakerpomperada.blogspot.com

 * jakerpomperada@gmail.com 

 

 * Machine Problem

  Write a C# sharp program that will ask two integers 

  and display it's sum , difference , product ,quotient and remainders . */


 

namespace Basic_Arithmetic

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.Write("\n\n");

            Console.Write("\tBasic Arithmetic in C# ");

            Console.Write("\n\n");

            Console.Write("\tGive First Value : ");

            int val_1 = Convert.ToInt32(Console.ReadLine());


            Console.Write("\tGive Second Value : ");

            int val_2 = Convert.ToInt32(Console.ReadLine());


            Console.Write("\n");

            Console.Write("\tDisplay Results ");

            Console.Write("\n\n");

            Console.WriteLine("\t{0} + {1} = {2}", val_1, val_2, val_1 + val_2);

            Console.WriteLine("\t{0} - {1} = {2}", val_1, val_2, val_1 - val_2);

            Console.WriteLine("\t{0} x {1} = {2}", val_1, val_2, val_1 * val_2);

            Console.WriteLine("\t{0} / {1} = {2}", val_1, val_2, val_1 / val_2);

            Console.WriteLine("\t{0} mod {1} = {2}", val_1, val_2, val_1 % val_2);

            Console.ReadKey();

        }

    }

}




Monday, November 1, 2021

One-Dimensional Array in C

One-Dimensional in Array in C

 A simple program that demonstrates a one-dimensional array in the C programming language.

  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 at 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.





Program Listing


/* one_dimensional_array.c

   Prof. Jake Rodriguez Pomperada, MAED-IT, MIT

   www.jakerpomperada.blogspot.com and www.jakerpomperada.com

   jakerpomperada@gmail.com

   Bacolod City, Negros Occidental Philippines.

*/



#include <stdio.h>


int main()

{

    int arr[7],a=0;


    printf("\n\n");

printf("\tOne Dimensional Array in C");

printf("\n\n");

    for(a=0; a < 7; a++)

    {

        printf("\tGive Value in a[%d]: ", (a+1));

        scanf("%d", &arr[a]);

    } 


    printf("\n\n");

    printf("\tList of elements of the array: \n\n");

    printf("\t");

    for(a = 0; a < 7; a++)

    {

        printf("%d ", arr[a]);

    }

printf("\n\n");

printf("\tEnd of Program");

printf("\n\n");

       

    return 0;

}

Employee's Contact Details System in C

Employee's Contact Details System in C

 A simple employees contact details system in C programming language.

  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 at 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.





Program Listing

/*employees_details.c

 Authors   : Jake R. Pomperada,MAED-IT, MIT

 Emails    : jakerpomperada@gmail.com 

 Tool      : Dev C++ Version 5.11

 Date     :  November 1, 2021  Monday  9:53 AM

 */


#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <ctype.h>

#include <string.h>


main( )

{

FILE  *fp, *ft ;

char  another, choice ;

struct employees

{

char  emp_id[200];

char  name[200];

char  sex;

char  address[200];

char  telephone[200];

char  mobile[200];

char  email[200];

};


struct employees info ;

char employee_id[200];

int flag=0;


long int  recsize ;

fp = fopen ("RECORDS.DAT", "rb+" ) ;


if ( fp == NULL )

{

fp = fopen ("RECORDS.DAT", "wb+" ) ;


if ( fp == NULL )

{

puts ("Cannot open file" ) ;

exit(0) ;

}

}


recsize = sizeof ( info ) ;


while (1)

{

        system("CLS");

        printf("\n");

        printf("\n\t===========================================");

        printf("\n\tEMPLOYEES CONTACT DETAILS SYSTEM IN C ");

        printf("\n\t\t\tCreated By");

        printf("\n\t   Jake R. Pomperada, MAED-IT, MIT");

        printf("\n\t===========================================");

printf("\n\n");

printf ( "\t1. ADD EMPLOYEE'S RECORD") ;

printf("\n");

printf ( "\t2. DISPLAY EMPLOYEE'S RECORD" ) ;

printf("\n");

printf ( "\t3. UPDATE EMPLOYEE'S RECORD" ) ;

printf("\n");

printf ( "\t4. SEARCH EMPLOYEE'S RECORD" ) ;

printf("\n");

printf ( "\t5. DELETE EMPLOYEE'S RECORD" ) ;

printf("\n");

printf ( "\t6. QUIT PROGRAM" );

printf("\n\n\n");

printf ("\tSELECT YOUR CHOICE : ") ;

fflush (stdin) ;

choice = getche() ;

switch (choice)

{

case '1' :

fseek (fp, 0 ,SEEK_END) ;

another = 'Y' ;

while ( another == 'Y' )

{

system("cls");

printf("\n\n");

                    printf("\t=== Add New Employee's Record in the Database ===");

                    printf("\n\n");

printf("\tEnter Employees ID Number    : ");

scanf("%s",&info.emp_id);

printf("\tEnter Employee's Name        : ");

fflush(stdin);

gets(info.name);

printf("\tEnter Gender M/F             : ") ;

                    info.sex = toupper(getche());

                    printf("\n");

                    printf("\tEnter Home Address           : ");

                    fflush(stdin);

gets(info.address);

printf("\tEnter Telephone Number       : ");

                    fflush(stdin);

gets(info.telephone);

printf("\tEnter Mobile Number          : ");

                    fflush(stdin);

gets(info.mobile);

printf("\tEnter Email Address          : ");

fflush(stdin);

gets(info.email);

    fwrite (&info, recsize, 1, fp ) ;

printf("\n\n");

printf ("\n\tAdd another Record (Y/N)  : ") ;

fflush (stdin) ;

another = toupper(getche()) ;

}


break ;


case '2' :

    system("cls");

rewind (fp);

printf("\n\n");

                printf("\t=== View Employee's Records in the Database ===");

                printf("\n");

while ( fread ( &info, recsize, 1, fp ) == 1 )

         {

    printf("\n\tEmployee's ID Number  : %s",info.emp_id);

        printf("\n\tEmployee's Name       : %s",info.name);

    printf("\n\tGender                : %c",info.sex);

    printf("\n\tHome Address          : %s",info.address);

    printf("\n\tTelephone Number      : %s",info.telephone);

    printf("\n\tMobile Number         : %s",info.mobile);

    printf("\n\tEmail Address         : %s",info.email);

        printf("\n\n");

        }

            system("pause");

            break ;


case '3' :

               rewind (fp);

another = 'Y' ;

while (another == 'Y')

{

                    system("cls");

                    printf("\n\n");

                    printf("\t=== Update Employee's Records in the Database ===");

                    printf("\n\n");

    printf("\tEnter Employee's ID Number    : ");

scanf("%s",&employee_id);

printf("\n");

rewind (fp) ; 

while (fread( &info, recsize, 1, fp ) == 1 )

{

                    if ( strcmp (info.emp_id, employee_id ) == 0 )

                    {

                    printf("\tEnter Employee's ID Number    : ");

scanf("%s",&info.emp_id);

printf("\tEnter Employee's Name         : ");

fflush(stdin);

gets(info.name);

printf("\tEnter Gender M/F              : ") ;

                    info.sex = toupper(getche());

                    printf("\n");

                    printf("\tEnter Home Address            : ");

                    fflush(stdin);

gets(info.address);

printf("\tEnter Telephone Number        : ");

                    fflush(stdin);

gets(info.telephone);

printf("\tEnter Mobile Number           : ");

                    fflush(stdin);

gets(info.mobile);

printf("\tEnter Email Address           : ");

fflush(stdin);

gets(info.email);

                    printf("\n\n");

                    printf("\tEmployee's records has been updated in the database.");

                    printf("\n\n");

                    system("pause");

fseek ( fp, - recsize, SEEK_CUR ) ;

fwrite ( &info, recsize, 1, fp ) ;

break ;

                    }

                }

             if (strcmp(info.emp_id,employee_id) != 0 )

                    {

                        printf("\n\n");

                        printf("\tNo Record in the Database.");

                        printf("\n");

                        system("pause");

                        break;

                    }

                    printf("\n\n");

printf ("\n\tUpdate Another Record (Y/N) : " ) ;

fflush (stdin) ;

another = toupper(getche());

}

break ;

case '4' :

                rewind (fp);

another = 'Y' ;

while ( another == 'Y' )

{

                  system("cls");

printf("\n\n");

                    printf("\t=== Search Employee's Records in the Database ===");

                    printf("\n\n");

    printf("\tEnter Employee's ID Number     : ");

scanf("%s",&employee_id);

    rewind (fp) ;

    printf("\n");

while (fread( &info, recsize, 1, fp ) == 1 )

{

if (strcmp(info.emp_id,employee_id) == 0 )

{

                        printf("\n\tEmployee's ID Number  : %s",info.emp_id);

        printf("\n\tEmployee's Name       : %s",info.name);

        printf("\n\tGender                : %c",info.sex);

        printf("\n\tHome Address          : %s",info.address);

    printf("\n\tTelephone Number      : %s",info.telephone);

    printf("\n\tMobile Number         : %s",info.mobile);

    printf("\n\tEmail Address         : %s",info.email);

                        printf("\n\n");

                        system("pause");

                        break;

                }

}


            if (strcmp(info.emp_id,employee_id) != 0 )

                    {

                        printf("\n");

                        printf("\tSorry No Record Found in the Database.");

                        printf("\n\n");

                        system("pause");

                        break;

                    }

                    printf("\n");

printf ("\n\tSearch Another Employee's Record? (Y/N) : " ) ;

fflush (stdin) ;

another = toupper(getche());

}

break ;


case '5' :

another = 'Y' ;

while ( another == 'Y' )

{

system("cls");

flag=0; 

printf("\n\n");

                    printf("\t=== Delete Employee's Records in the Database ===");

                    printf("\n\n");

printf("\tEnter Employee's ID Number      : ");

scanf("%s",&employee_id);

printf("\n");

    ft = fopen ("TEMP.DAT", "wb") ;

rewind (fp) ;

while (fread (&info, recsize, 1, fp) == 1 )

{

if (strcmp(info.emp_id, employee_id) != 0 )

fwrite(&info, recsize, 1, ft ) ;

else

                            flag=1;

}

fclose (fp) ;

fclose (ft) ;

remove ("RECORDS.DAT") ;

rename ("TEMP.DAT", "RECORDS.DAT") ;

fp = fopen ("RECORDS.DAT", "rb+") ;

                  if(flag==1) {

                        printf("\n\n");

                        printf("\tRecord Successfully Deleted From the Database.");

                        printf("\n\n");

                        system("pause");

                    }

else if (flag!=1) {

                        printf("\n\n");

                        printf("\tSorry Record Not Found in the Database.");

                        printf("\n\n");

                        system("pause");

                    }

                        printf("\n\n");

                        printf( "\tDelete Another Employee's Record? (Y/N) " ) ;

                        fflush ( stdin ) ;

                        another = toupper(getche());

}

break ;

case '6' :

fclose (fp) ;

printf("\n\n");

printf("\t\tThank You For Using This Program !!!   ");

printf("\n\n");

system("PAUSE");

exit(0);

}

}

} /* End of the Code */