Developers Archive for December, 2006

mhash_keygen_s2k

mhash_keygen_s2k Friday, December 29th, 2006

mhash_keygen_s2k
Name
mhash_keygen_s2k — Generates a salted key based on the specified hash algorithm.
Synopsis
string mhash_keygen_s2k(hash, password, salt, bytes);
const hash: mhash constant representing a specific hash algorithm
string password: User password
string salt: Random data
int bytes: Key length
Returns
Salted key value as a string; FALSE on error

Description
mhash_keygen_s2k() generates a key of bytes length from a user-given password , using the hash hash . This produces the “Salted S2K” data element described in RFC 2440. This function can be used to compute checksums, message digests, and other signatures.

The salt is a random piece of data used to generate the key. To check the key, you must also know the salt , so it’s a good idea to append the salt to the key for checking. As long as password is not sent as well, your hash is still secure. In addition, salt has a fixed length of 8 bytes and will be padded with zeros if you supply fewer bytes.

Example
<?php
// This is a bad salt!
$salt = “asdf1234″;
$password = “pass”;
$hash = mhash_keygen_s2k(MHASH_MD5, $password, $salt, 16);

$key = bin2hex($hash);

echo $key;
?>

Using Hash Table object in asp.net

Using Hash Table object in asp.net Friday, December 29th, 2006

The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick searches can be made for values by searching through their keys.

Items are added to the Hashtable with the Add() method.

The following code creates a Hashtable named books and three elements are added:

 Hashtable books=New Hashtable
 books.Add(”b1″,”book1″)
 books.Add(”b2″,”book2″)
 books.Add(”b3″,”book3″)
 

Data Binding
A Hashtable object may automatically generate the text and values to the following controls:

asp:RadioButtonList
asp:CheckBoxList
asp:DropDownList
asp:Listbox

To bind data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:

<html>
<body><form runat=”server”>
<asp:RadioButtonList id=”rb” runat=”server”
AutoPostBack=”True” /></form></body>
</html>

Then add the code that builds the list:

protected void Page_Load(object sender, EventArgs e)
{
  Hashtable books=New Hashtable
  books.Add(”b1″,”book1″)
  books.Add(”b2″,”book2″)
  books.Add(”b3″,”book3″)
  rb.DataSource=books
  rb.DataValueField=”Key”
  rb.DataTextField=”Value”
  rb.DataBind()
}
Then we add a function to be executed when the user clicks on an item in the RadioButtonList control. When a radio button is clicked, a text will appear in a label:

Public void displayMessage()
{
lbl1.text=”Your favorite country is: ” + rb.SelectedItem.Text
}

</script>
<html>
<body>
<form runat=”server”>
<asp:RadioButtonList id=”rb” runat=”server”
AutoPostBack=”True” onSelectedIndexChanged=”displayMessage” />
<p><asp:label id=”lbl1″ runat=”server” /></p>
</form>
</body>
</html>

Using ArrayList in Asp.net

Using ArrayList in Asp.net Friday, December 29th, 2006

The ArrayList object is a collection of items containing a single data value.
Items are added to the ArrayList with the Add() method.

The following code creates a new ArrayList object named books and three items are added:

  ArrayList books = new ArrayList();
  books.Add(”book1″);
  books.Add(”book2″);
  books.Add(”book3″);
 
By default, an ArrayList object contains 16 entries. An ArrayList can be sized to its final size with the TrimToSize() method:

  books.TrimToSize();

An ArrayList can also be sorted alphabetically or numerically with the Sort() method:

  books.Sort();

To sort in reverse order, apply the Reverse() method after the Sort() method:

  books.Sort();
  books.Reverse();

Data Binding to an ArrayList
An ArrayList object may automatically generate the text and values to the following controls:

asp:RadioButtonList
asp:CheckBoxList
asp:DropDownList
asp:Listbox

To bind data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:

<html>
<body><form runat=”server”>
<asp:RadioButtonList id=”rb” runat=”server” />
</form></body>
</html>

Then add the code that builds the list and binds the values in the list to the RadioButtonList control in the code behind:

protected void Page_Load(object sender, EventArgs e)
{
  ArrayList books = new ArrayList();
  books.Add(”book1″)
  books.Add(”book2″)
  books.Add(”book3″)
  books.TrimToSize()
  books.Sort()
  rb.DataSource=books
  rb.DataBind()
}

The DataSource property of the RadioButtonList control is set to the ArrayList and it defines the data source of the RadioButtonList control. The DataBind() method of the RadioButtonList control binds the data source with the RadioButtonList control.

Note: The data values are used as both the Text and Value properties for the control. To add Values that are different from the Text, use either the Hashtable object or the SortedList object.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.