image05 image06 image07

300x250 AD TOP

Text Widget

Total Pageviews

Subscribe us

Contact Us

Name

Email *

Message *

Powered by Blogger.

You can also receive Free Email Updates:

Popular Posts

Followers

Feature Label Area

Add this blog to my Technorati Favorites!

Visit blogadda.com to discover Indian blogs
IndiBlogger - The Largest Indian Blogger Community

My Blog's BUDDAY!!!
Get your own free Blogoversary button!
Software
Resa till New York
Top Blogs
blog search directory

Monday, 1 October 2012

Tagged under: , ,

Creating a Barcode in PHP



A barcode is an optical machine-readable representation of data relating to the object to which it is attached. Originally barcodes represented data by varying the widths and spacings of parallel lines, and may be referred to as linear or one-dimensional (1D).
A Barcode is generally used to map a product to its characteristics. For example, a barcode is commonly used to identify the product code, and map the unique code to the price of the product in the database. This barcode is a widely used technique.
Creating a barcode is a fairly easy job, provided you have the right font for it. I found one, with relative ease, and guess what....it was free of cost!! I have added the font file in free3of9.zip folder, which can be downloaded from the download box present in the sidebar. I really want to thank the creator of this font, for his hardwork, and also making his work available free of charge.
Once you have the right font, the rest is quite an easy job. we will use the basic function in PHP, viz

imagettftext($img, $fontsize, $angle, $xpos, $ypos, $color, $fontfile, $text);
Now, create a PHP file, which I have named as index.php in my case.

Include the following code in the file:



//The code for which barcode needs to be generated
$number = '*8108137*';

//GIve the path of the font file
$barcode_font = 'FRE3OF9X.TTF';

$width = 200;
$height = 80;

$img = imagecreate($width, $height);

// First call to imagecolorallocate is the background color
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);

// imagettftext($img, $fontsize, $angle, $xpos, $ypos, $color, $fontfile, $text);
imagettftext($img, 36, 0, 10, 50, $black, $barcode_font, $number);

header('Content-type: image/png');

imagepng($img);
imagedestroy($img);

?>
Here, in this code, the code for which barcode needs to be generated is stored in the $number variable. Care needs to be taken that the code starts and ends with an asterisk (*). The barcode scanner starts looking for an asterisk, and then scans ahead of * till it reaches the ending *.
For example, if the code is 1234567, it is represented as *1234567*.
Now, this number, or code can be passed from another page, using the GET method of PHP.
Your code is now ready!! Open your project in localhost, and see your code generating a Barcode!! 

If you found the post helpful, please share!!

Saturday, 14 July 2012

Tagged under: , ,

Secure Login Code using PHP and MySQL / Preventing SQL Injection using PHP

Many Web pages accept parameters from web users and generate SQL queries to the database. SQL Injection is a trick to inject SQL script/command as an input through the web front end.

Your application may be susceptible to SQL Injection attacks when you incorporate invalidated user input into the database queries. Particularly susceptible is a code that constructs dynamic SQL statements with unfiltered user input.



Consider the following example code:
Sql DataAdapter myCommand = new SqlDataAdapter(
"Select * from Users
Where UserName = ' "+txtuid.Text+" ", conn);

Attackers can inject SQL by terminating the intended SQL statement with the single quote character  followed by a semicolon character to begin a new command and then executing the command to their choice. Consider the following character string entered into the .txtuid field.
' OR 1=1
This results in the following statement to be submitted to the database for execution:
SELECT * FROM Users WHERE UserName = ' ' OR 1 = 1;

Because 1=1 is always true, the attacker retrieves very row of data from the user table.

Now, to prevent such an attack, a secure login technique is required. Here, in this article, we discuss the coding of a secure login script using PHP and MySQL.




Step I: Create a database and a table 'members' in it:


CREATE TABLE `members` (
`username` varchar(20),
`password` varchar(128)
)



Step II: Create a Login Form:


<form action="process_login.php" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="Login" />
</form>


Connect to MySQL Server:


$host = 'localhost'; // Host name Normally 'LocalHost'
$user = 'root'; // MySQL login username
$pass = ''; // MySQL login password
$database = 'test'; // Database name
$table = 'members'; // Members name

mysql_connect($host, $user, $pass);
mysql_select_db($database);


Step III: Now, you need to provide mechanism to avoid SQL Injection. For this, escape special characters like ", ', \

We can escape special characters (prepend backslash) using mysql_real_escape_string or addslashes functions. In most cases PHP will this do automatically for you. But PHP will do so only if the magic_quotes_gpc setting is set to On in the php.ini file.
If the setting is off, we use mysql_real_escape_string function to escape special characters. If you are using PHP version less that 4.3.0, you can use the addslashes function instead.


name = mysql_real_escape_string($_POST['username']);
$password = md5($_POST['password']);

$result = mysql_query("SELECT * FROM $table WHERE username = '$username' AND password = '$password'
");


Here, we use the MD5(Message Digest 5) Algorithm, that generates the message digest for the password. So, while writing the script for registration page, care must be taken that the md5 of the password entered by the user must be stored in the database, instead of the actual text password.

Validating the login:


if(mysql_num_rows($result))
{
// Login
session_start();
$_SESSION['username'] = htmlspecialchars($username);
}
else
{
// Invalid username/password
echo '<p><strong>Error:</strong> Invalid username or password.</p>';
}

// Redirect
header('Location: http://www.example.com/loggedin.php');
exit;


You are done!! This code will help prevent the SQL injection problem. However, it must be noted that no script is 100% secure. So, it is advisable to provide multilevel security process, which make the login more secure.

Tuesday, 10 July 2012

Tagged under: , ,

Auto Refresh a Web Page using AJAX

AJAX is nothing but Asynchronous JavaScript and XML. It is not a new programming language, but a new way to use the existing standards. It is the art of exchanging data with a server, and updating parts of a web page without reloading the whole page!!

Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. JavaScript and XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

 Using JavaScript for periodically refreshing a page can be quite annoying, as the entire page reloads time to time. Hence, a better option would be to use AJAX.
Include the following code in the <head> section of the page....



The section now refreshes after every 20 seconds. You can change the 20000 value to suite your requirements.
You can remove the ".fadeOut('slow')" and ".fadeIn(Slow)" parts if you want the page to be refreshed unnoticed.

Now, whichever section you want to be refreshed, must be included within the <div id="loaddiv"> tags as follows:



You are now done!! Enjoy as your page refreshes without you noticing!!

Saturday, 7 July 2012

Tagged under: ,

Checking if your Computer has been violated and infected with DNS Changer

Domain name system (DNS) is the part of the internet that links a website name (say example.com) to its numerical internet protocol equivalent (say 123.456.789.098). As the cyber world awaits Monday, when the FBI will shut down servers affected by the DNS changer malware, there is still a day to check if your system has been affected.
Various cyber security firms are offering free solutions. You can visit www.mcafee.com/dnsdetect to check if your computer is infected.
You can also manually check if your DNS server has been changed.

Step I: Open Command Prompt.
           Navigate to Start-> Run.  Type cmd and hit enter.


StepII: (For Windows XP)Type ipconfig/all and hit enter.
           (For Windows 7) Type ipconfig/allcompartments/all and hit enter.


Step III: (For Windows XP) The command you entered displays information about your computer’s network settings. Read the line starting with "DNS Servers". There might be two or more IP addresses listed there. These are the DNS servers your computer uses. Write down these numbers.

(For Windows 7) The output will be very long, since Windows7 by default has support for IPv6. Most likely, you want to look for the IPv4 information under the section entitled “Ethernet adapter…”. Look for the “DNS Servers” line, and write down these numbers. There may be two IP addresses listed there.

Step IV: Check if your DNS settings are OK

Compare your DNS settings with the known malicious Rove DNS settings listed below:
Starting IPEnding IPCIDR
85.255.112.085.255.127.25585.255.112.0/20
67.210.0.067.210.15.25567.210.0.0/20
93.188.160.093.188.167.25593.188.160.0/21
77.67.83.077.67.83.25577.67.83.0/24
213.109.64.0213.109.79.255213.109.64.0/20
64.28.176.064.28.191.25564.28.176.0/20

 What if you are infected?
If you computer is infected, please refer the page that list tools to clean DNS Changer and other self help guides to clean your computer – http://www.dcwg.org/fix/

Sunday, 1 July 2012

Tagged under: , ,

How to create CAPTCHA using PHP

CAPTCHA: Completely Automated Public Turing Test To Tell Computers and Humans Apart.

A CAPTCHA is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. For example, humans can read distorted text as the one shown alongside, but current computer programs can't:

The term CAPTCHA (for Completely Automated Public Turing Test To Tell Computers and Humans Apart) was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper and John Langford of Carnegie Mellon University.

Generating a simple CAPTCHA and its verification is quiet a simple task using PHP. In this post, I would do the same, but the CAPTCHA generated would be a simple one, while the reader can add his own creativity to it later!!

  • Step I: Create a file captchaimg.php, and add the following code to it:



You can check the above file by opening it in your browser. Everytime you refresh, a new, random alphanumeric string is generated in the CAPTCHA.
  • Step II: Create a form form.php, and add the following code to it:


Now, this is it!! Your basic CAPTCHA is ready!! It will look like below:

Another Example:
For this, you need to include a font file in your project folder. I have used AngelicWar.ttf. Download the font from the download box alongside.
Now, Overwrite the file captchaimg with the following code:


Now, this will result in following CAPTCHA:


For the following CAPTCHA use cheapink.ttf from the download box alongside.



You can enhance it by using two different strings in a single CAPTCHA image, or using some string characteristics.

Want help in creating more creative CAPTCHA?? Feel free to Contact Me.

Thursday, 14 June 2012

Tagged under: , ,

Connecting C# to MySQL database / C# connection String for MySQL

In many cases it becomes imperative to connect C# to MySql, the prominent reason being the inherent simplicity of MySql. We have generally used the usual connection string to connect PHP to MySql. Connecting C# to MySql is similar.
We first need to use the connection string to establish the connection with MySql. Then, we use the SQL queries to carry out the Creation, Insertion, Update & Delete operations.


Before we do anything, first you need to download and install mysql-connector. You can get this connector from MySQL :: Download Connector/Net.

Once you install this connector, you need to add it as a reference in your C# project. You can do this by navigating to Project -> Add Reference. Then go to the .Net tab, and search for MySql.Data, and add it as a reference.

Now you need to include MySql.Data.MySqlClient at the start of the code. Add this at the start:


Now, you can use this connection string for establishing the connection:


Now, you can use 'con' when you need to fire any query.

Now, lets get into details of using sql queries.

1. CREATE TABLE:

                 
2. INSERT:

                 
3. UPDATE:

                 
4. DELETE:


5. SELECT:


Finally, you need to close the connection, after you finish executing the queries. You can do this by writing:
                 


Friday, 1 June 2012

Tagged under: , , ,

Generating a Unique Hardware Fingerprint for Software Licensing

Generating a hardware fingerprint is the most commonly sought technique to ensure security in case of softwares. There can be various methods of generating the hardware fingerprint, using different languages. However, the important thing to decide is, which devices to consider while generating the fingerprint.

For licensing purposes, the best and secure way is to generate a unique key for the client's machine and provide a corresponding license key for that key. The key can be generated using the unique id of the client's computer motherboard, BIOS and processor. When you get these IDs, you can generate any key of your preferable format.


In this post, I will get into the details of generating the unique fingerprint for the user's system.


Step I: Adding References:


First of all, you need to add the following references to your project.
1. System.Drawing
2. System.Management
3. System.Windows.Forms
For doing this, navigate to Project in the Menu Bar--> Add References-->.Net


Step II: Starting to Code


Add the following code at the start.


Now, you can use this unique hardware fingerprint in further hashing, to authenticate the user system!!



You can for further assistance.

Tuesday, 1 May 2012

Tagged under: , ,

Solution for "Installation Error 0X80004002"

I was having a tough time installing Google Drive. When the setup was run, it gave an error message saying Google Update Installation failed, with error 0X80004002. This error is very common & occurs while installing Google products, like Chrome, Drive.
I tried to search for the solution but in vain. So I took a seemingly daring way, to solve this problem, and guess what...it worked!!!
Though this seems to be a crude way, it worked for me:

1. I Uninstalled all the Google related softwares from my PC, like Chrome, GTalk, Google Earth, Picasa.
2. Then open Run, and type regedit. This opens the Registry Editor.
3. Browse to HKEY_CURRENT_USER in the side bar.
4. Browse Software, and look for Google.
5. Right Click, and select DELETE.
6. Now close the Registry Editor, and try to install the Google related application again.

Had a tough time while reinstalling all my other Google applications though!!

Please contribute, if you have any better solution!!

For me, it worked...hope it works for you!!



You can for further assistance.

Saturday, 31 March 2012

Tagged under: , , ,

Sending email using PHP...(PHPMailer)

Sending emails using PHP is an easy task...Just a few steps and you are through!!

Step I: Download PHPMailer
The very first thing that needs to be done is, downloading the PHPMailer package. This package contains all the methods for sending simple mails, to sending mails with attachments!!
You can download the package from: PHPMailer

Step II: Starting to Code
Create a new php file test.php and copy the following code:
(Note: test.php file should be in the same folder as the extracted PHPMailer package)



The above code uses the gmail SMTP server...You have to mention the username and password of your gmail account!!

This is it!! You are now all ready to send mail!!

My next post will include sending attachments in emails....and also using mail() method!! So, keep visiting!!

You can for further assistance.

Tuesday, 7 February 2012

Tagged under: , , ,

Macromedia Flash 8

Flash is a drawing and animation package designed to work with vector graphics. It creates animations which can include sounds, music and interactivity, and which are optimised for use on the web. Hence, the files it produces are small and designed for streaming. Furthermore, all the elements which form part of a flash movie are embedded within the movie. This means that, unlike a standard web page which relies on the fonts and resources on the client machine, as long as the user has the flash player installed, the movie will play exactly as you design it.
                The default file extension for a Flash file is .fla. Flash movie files can also be published in .htm, .swf, .jpg, .exe, .png or as a projector file.

Layout:

§  Toolbox:
The toolbox contains all tools necessary for drawing, viewing, coloring and modifying your objects. Each tool in the toolbox comes with a specific set of options to modify that tool. The diagram below outlines the grouping of tools.

            Arrow tool:
It is used to select a single or a group of objects.

            Lasso tool:
It is used to select objects by drawing either freehand or straight-edged selection area.

           Text tool (“A”):
It is used to include custom text with various options like selecting a font, colour, style, etc.

            Line tool:
It is used to draw a line with options of line width and style.

            Oval tool:
It is used to draw an oval object. Ovals can be filled with colours and outlines can be customized.

            Rectangle tool:
It is used to draw a rectangular object.

            Pencil tool:
The Pencil tool is used to draw lines, shapes or freehand forms. The pencil tool has three modifiers:  straighten, smooth and ink. Flash straightens or smoothens the freehand drawing made by this tool.

            Brush tool:
The Brush tool allows you to draw brush-like strokes for creating special effects, including calligraphic effects and paintings with an image. The brush tool has the following modifiers: paint options, fill colour, gradient, brush size, brush shape, lock fill.

            Paint Bucket tool:
It is used to change the colour of the existing paint and fill empty areas surrounded by lines.

Inkbottle tool:
It allows to stroke lines and shapes with only solid colours but no with no gradients or bitmaps.

            Eraser tool:
It erases lines and fills. It can also erase selected items such as only lines or only fills, etc.

Timeline:
The timeline indicates what frame you are at and also indicates the number of frames in your movie. Within the timeline you will find layers - you can have any number of layers within a movie and it is within these layers that you put your graphics, text, and sounds. 
Work Area:
The Work Area is not viewable when you play your movie, so it is a place to work on objects or if you want your objects to “fly in” to your movie then start them from the Work Area.


Stage:
The Stage is where all viewable objects lie. Anything on the stage is seen by the user and will be seen in the animation. 



You can for further assistance.