Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
Objectives Connect to MySQL from PHP
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
02/09/2015 Intro PHP & MySQL 1 Helen Hastie Room: EMB244 Material available on Vision (modified from slides by Monica Farrow) F27DB Introduction.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
INTERNET APPLICATION DEVELOPMENT For More visit:
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Tutorial 10 Adding Spry Elements and Database Functionality Dreamweaver CS3 Tutorial 101.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
PHP and MySQL for Client-Server Database Interaction Chapter 10.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
INTERNET APPLICATION DEVELOPMENT Practical on Sessions.
Multifarious Project A personal -system Team Members Abdullah Alghamdi Metaib Alenzai Mohammed Alshehri Hamd Alshamsi.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
SQL INJECTIONS Presented By: Eloy Viteri. What is SQL Injection An SQL injection attack is executed when a web page allows users to enter text into a.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
MEMBERSHIP AND IDENTITY Active server pages (ASP.NET) 1 Chapter-4.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Sessions Brendan Knight A visitor accessing your web site is assigned a unique id. This id links to specific data that remains on the server. Sessions.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
PHP: Security issues FdSc Module 109 Server side scripting and
Chapter 13 Security Methods Part 3.
Presentation transcript:

Controlling Web Site Access Using Logins CS 320

Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP page that validates the login PHP page queries database for username and password  If found, stores their userid (customerid, or whatever is the primary key identifying them) in a session variable and displays the next page  If not found, returns them to the initial login page with an appropriate message (Username or password incorrect)  Example: gin.php gin.php

Basic Concepts Session variables Working with session variables Command to forward the user to a different page PHP include command Preventing a user from directly accessing a page that requires a login What is a SQL Injection attack?

Session Variables When you request a Web page, the Web server creates a session object corresponding to your browser session  This information is stored in the Web server's main memory  Each time you connect to a Web site, you create a new session  If you connect to the same Web site on the same client computer using 2 different browsers, each browser makes a separate session

Session Variables Sessions have attributes that you can retrieve and display using program commands A program running on the Web server can create session variables that store data values associated with a specific browser session  Values are stored in Web server RAM and associated with the session object

Session Timeout Intervals By default, server/browser sessions "time out" (close) after a specific period of inactivity:  Microsoft IIS: 20 minutes  Tomcat: 30 minutes  You can change these values to longer/shorter ones At that point, the session closes and the session object is destroyed  All session variable data is lost!

Login Approach Using a Session Variable Run a database query to determine if username/password is valid If it is, create a session variable Variable is then checked (to see if it exists) by other pages requiring login  All of these pages redirect to the login page if this variable isn’t found

Using session variables in PHP Before storing or retrieving session variables  Start a new session or resume the existing session with this php code at the top of every page using session variables – it must be before any html or text is sent  Registers the user's session with the server  Assigns a UID (unique identification number) for the user's session if this is the first page requested by this browser from the server

PHP Session Variable Commands To create a session variable: To create a session variable and assign an initial value: To read a session variable and assign its value to a PHP program variable:

PHP Session Variable Commands To unset a session variable To test for existence (assumes already assigned the session variable value to a variable named $currUserID) <? php if (is_null($currUserID) == true) { //wasn't found, do something … } ?>

PHP command redirecting to a different page header("Location:Login.php"); What does this command really do?  From the Web server’s PHP page to the browser: Sends a request to the user’s browser asking the user’s browser to in turn send back a request for the specified page  From the browser to the Web server: Receives the request from the server and sends back to the Web server a request for the specified page  And from the Web server to the browser: Sends back the newly requested page Must be placed before any html is sent to the browser!

Login page sequence Candy_Login.php 1.Receive user and password values as parameters 2.Run query to retrieve CUST_ID based on username and password values 3.If succeed: i. Create session variable = CUST_ID value ii. Go to next page in application If fail: i. Go back to CandyLogin.php and display an error message processCandyLogin.php

Candy_Login.php Code <?php session_start(); //remake the session variable in case it already exists unset($_SESSION["cust_id"]); ?> Candy Login <?php error_reporting(NULL); $msg = $_REQUEST["msg"]; if($msg == "invalidLogin") { ?> Invalid Login - Please try again

processCandyLogin.php Code <?php session_start(); // Add code to retrieve username and password from the previous page // and store them in PHP variables $cust_username = $_REQUEST["cust_username"]; $cust_password = $_REQUEST["cust_password"]; //Add code to include the file that contains the connection commands include("Includes/connectMySQL.php"); //Add code to create and execute the database query $query = "SELECT cust_id FROM candy_customer ". "WHERE cust_username = '". $cust_username. "'". " AND cust_password = '". $cust_password. "'"; $result = mysql_query($query) or die(mysql_error()); //determine number of rows retrieved $num_rows=mysql_num_rows($result); mysql_close();

processCandyLogin.php Code //continued from previous slide //add code to validate login if($num_rows > 0) { $row = mysql_fetch_array($result); $_SESSION["cust_id"] = $row["cust_id"]; header("Location:Menu.php"); } else { header("Location:candy_login.php?msg=invalidLogin"); } ?>

Candy_Login.php Code revisted <?php session_start(); //remake the session variable in case it already exists unset($_SESSION["cust_id"]); ?> Candy Login <?php error_reporting(NULL); $msg = $_REQUEST["msg"]; if($msg == "invalidLogin") { ?> Invalid Login - Please try again

Preventing a user from directly accessing a page that requires a login Test for the existence of the session variable Put this code at the top of pages that shouldn't be accessed unless the user has logged in successfully <?php session_start(); //attempt to retrieve the session variable value $userid = $_SESSION["cust_id"]; if(is_null($userid) == true) { // they haven't logged in - send them back to the login page header("Location:candy_login.php"); die(); } ?> Candy Login …

Moving database connection code to a separate file using an include PHP include command allows inserting contents of a file within the current file <?php session_start(); // Add code to retrieve username and password from the previous page // and store them in PHP variables $cust_username = $_REQUEST["cust_username"]; $cust_password = $_REQUEST["cust_password"]; //Add code to include the file that contains the connection commands include("Includes/connectMySQL.php");

Moving login verification to separate file Contents of the included file: <?php // add code connecting to the MySQL database mysql_connect("dario.cs.uwec.edu",“STEVENDE","******") or die("Could not connect to MySQL. The reported SQL error is:". mysql_error()); mysql_select_db(“STEVENDE") or die("Could not connect to the database. The reported SQL error is: ". mysql_error()); ?> Includes/connectMySQL.php

What is a SQL Injection Attack? A form of attack on a database-driven Web site in which the attacker executes unauthorized SQL commands Possible when a query is concatenated together from user inputs and tests to see if any rows are retrieved

Performing the Attack: Enter a stolen username Enter password as: Search condition sent to DB (always evaluates as true):  All user rows returned to application  If application checking for 0 vs. more than 0 rows, attacker is in! Foo’ OR ‘1=1 SELECT * FROM users WHERE username = ‘STEVENDE' AND Password = ‘Foo’ OR ‘1=1’

Database Dark Humor:

Bottom Line: TEST for SQL injection attacks! If your system allows them:  Research how to prevent based on your PHP version