Saturday, August 29, 2009

Cookies and Javascript

Handling cookies in Javascript
=================================



function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +
"; path=/";
}

Thursday, August 27, 2009

Regular expressions in javascript and Java

Regular expressions lets you to search a text in a text string or do a search and
replace a text in a text string.



Java Script:

Create the expression
================================================================================

var exp = /expression/;
Or
var exp = new RegExp("expression");

Testing availability of a text.
================================================================================

if(/text/.test("The text string.")) alert("Found text");

OR

if ("The text string".match(/text/)) alert("Match found for text");

Doing a search and replace.
================================================================================

var output = "The text string".replace(/text/g, "replacement");

OR

var re = new RegExp("text", "g");
var output = "The text string".replace(re,"replacement");

Using the /g OR "g" modifier makes sure that all occurrences of "text" are replaced


Splitting a text string by a delimiter
================================================================================

var myArray = "comma, separated, text, string".split(/,/);


Retrieving the part of the string that was matched
================================================================================

var mymatch = /text/.exec("The text string")

if (mymatch == null) {
alert("No match");
} else {
var s = "Match at position " + mymatch .index + ":\n";
for (i = 0; i < s =" s" mystringarr = "comma, separated, text, string" replaced = "change, delimiter, of, text, string" regex = "match this string" regex = "match.*" class ="=" mypattern =" Pattern.compile(" mymatcher =" myPattern.matcher("> The "^" says check the beginning of the text. [A-Z] specify range of
numbers.

Check for any text starting with a digit 1 to 5.
==============================================================================

^[1-5]

See reference [http://www.regular-expressions.info/reference.html] for details.

Tuesday, August 25, 2009

Password protect D-Link wireless router DSL-2640U

Security options to choose from.

Wired Equivalent Privacy (WEP) - Less secure (The key can be recovered from network sniffing)
Wi-Fi Protected Access (WPA and WPA2) - The recommended solution to WEP security problems.
WPA-PSK (Pre-shared key mode) is the personal mode which is designed for home and small office network setups.
WPA supports two encription methods to choose from.
TKIP - Temporal Key Integrity Protocol.
AES - Advanced Encryption Standard which is considered to be fully secured.


Seting up a security key (password)
===================================

Type http://192.168.1.1/ in your browser to open the router admin console.
Go to the wireless security tab and choose the follwing settings for each
option.
Network Authentication: WPA-PSK
WPA Pre-Shared Key (Password): Combination of numbers and letters.
WPA Group Rekey Interval: 0
WPA Encryption: AES
WEP Encryption: Disabled.

Following is a screenshot of the required settings.






Adding the wireless network password to Windows Vista


Setingup the password in Windows Vista can be done throught the "Manage Wireless Networks". Access "Manage Wireless Networks" from Control Panel>Network and Sharing Center>. Right click and select properties of the DLink network. Select the security tab and enter the following.
Security type: WPA-Personal
Encryption type: AES
Network security key: (Enter the previousely setup password)




Now your wireless network is fully protected.

Subscribe