Search Keyword:

This article will show and explain to you how to fire a simple AJAX request in CodeIgniter using Jquery.In this example we will have a form,with username and password field on it,check if the fields are empty and validate it against a correct username and password.You can check out the demo by clicking here.

Note:Database interactions and CodeIgniter’s form validation is not included in this tutorial, and it is up to you to use the functions mentioned in your own application when you will need it.This tutorial only shows how data is passed and returned via AJAX in your CodeIgniter application. Read the rest of this entry »

These functions are equivalent to PHP’s trim() and nl2br() function written in Javascript and are most useful in working with formatting text inputs and textareas values.Trim() strips whitespaces from the beginning and end of a string and nl2br() inserts HTML line breaks (<br />) and replaces newlines or carriage returns(Enter key) in a string.

The function:

function trimStr(input_string)
{
return input_string.replace(/^\s+|\s+$/g, ”);
}

function nl2brStr(input_string)
{
return input_string.replace(/(\r\n|\r|\n)/g, “<br />”);
}

Usage:

You can use the functions individually or by joining them together.See the demo for sample implementations by clicking here.

This function returns a more secure password hash by using SHA1 encryption algorithm with the combination of using a salt,returning a salted hash.Salt is a random bit of data,consisting of upper and lowercase letters with the combination of numbers and special characters to be included in the string you want to hash so we can avoid the possibility of dictionary hacks.If you are using PHP 5.12 or above,you might want to look at SHA2 (sha256,sha384,sha512) encryption algorithm.

The function:

function password_hash($username,$password)
{
$salt = “123456789ThisIStheSalt9876543210″;
return sha1($username . $password . $salt );
}

In this function, I had used a 32-character,combination of upper and lowercase letters and numbers salt.You can change it to whatever random string of data you have come up with.You can also use special characters too!(!@#$,etc.).I have included the username in the parameter of the function so the string to be hashed will be more longer (username + password + salt).

Usage:

if($_POST['register_button'])
{
/* Clean first your post variables against SQL injection and cross site scripting attacks, cleaning function is not included in this tutorial */

// hash the password using the inputed username and the password
$hashed_password = password_hash($username , $password);

//proceed to inserting details in your database
}

For example, when a user register on your page, his username is “myusername” and password is “mypassword”,we will take his username and password and hash it using the function. The outcome of the hash will be “d6bbfc3af54c4736839fd339715b6698fb7d23e2″ .Isn’t that more secure than storing the plain-text password in your database?Yes it is.Then you’re ready to store the generated hash in the password field of your database.

if($_POST['login_button'])
{
/* Clean first your post variables against SQL injection and cross site scripting attacks, cleaning function is not included in this tutorial */

// hash the password using the inputed username and the password
$hashed_password = password_hash($username , $password);

//proceed to check if username and password matches in your database

}

When a user logs-in,we will take his username and password and hash it again using the same function.Then we will proceed to validate the username and the hashed password with the details stored in the database.

Sponsored Links


Categories





Recent Comments

  • Musta: Very good tutorial for beginners who want to get an idea of the ajax implemtation via jquery. Thanx
  • admin: Hello Mous, Kindly look at this link: http://www.ryantetek.com/2009/ 10/how-to-hack-psp-brite-30...
  • mous: Sir pls help.. i have a psp 3000 with firmware 5.02 i tried the instructions above and it wont work on me.. it...
  • milo: i think the quick solution is to have the pagination in ajax otherwise it wont work as expected im not sure...
  • admin: Hello Milo, I haven’t tried it with pagination before.Maybe I’ll take a look at it and post some...