• Now Online : 38
  • admin@codemyne.net

Introduction

The best security practices concerning to web applications is storing sensitive data like passwords into the database while authenticating.

There are two terms: Encoding and Encryption. Here it is explained about Encoding but not Encryption.Click here for the differances :Encryption vs Encoding

Encoding is used to transform a set of Unicode characters into a sequence of bytes. Where as Decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters.

The Unicode Standard assigns a code point (a number) to each character in every supported script. A Unicode Transformation Format (UTF) is a way to encode that code point.
The Unicode Standard version 3.2 uses the following UTFs:

  • UTF-8, which represents each code point as a sequence of one to four bytes.
  • UTF-16, which represents each code point as a sequence of one to two 16-bit integers.
  • UTF-32, which represents each code point as a 32-bit integer.

This encoding and decoding can be used to stroe the passords of users in the database table. After encoding a string, it can be get back by decoding it.

A Hash function can also used to secure the data. A hash function is an algorithm that takes a variable-length string as the input and produces a fixed-length binary value (hash) as the output.
But once it is stored in the database ,the original value cannot be retrieved. So it is a one-way function.This can be explained in another aricle.

To secure sensitive data like passwords add some salt(additional string) to the string to be encoded. And while comparing the strings use the same salt by adding to the string and decode it. if both are same ,the result is true otherwise false.

The class used is : System.Text.Encoding

The given simple code encodes and decodes a string. In this example encoding type used is UTF8.You can use any UTF type like 8, 16, 32.

privatestring EncodeData(string sData)
{
    try
    {
        byte[] toencodeData = newbyte[sData.Length];
        toencodeData = System.Text.Encoding.UTF8.GetBytes(sData);
        //encodes all the characters into a specified sequence of bytesstring encodedData = Convert.ToBase64String(toencodeData);
        return encodedData;
    }
    catch (Exception ex)
    {
        thrownew Exception("Error in EncodeData" + ex.Message);
    }
}
publicstring DecodeData(string sData)
{
    System.Text.UTF8Encoding utf8encoder = new System.Text.UTF8Encoding();
    System.Text.Decoder utf8Decoder = utf8encoder.GetDecoder();
    byte[] tobedecode_byte = Convert.FromBase64String(sData);
    //converts the specified System.String,which encode binary data as base 64 digits,to an equivalent 8-bit unsigned integer array
    int char_Count = utf8Decoder.GetCharCount(tobedecode_byte, 0, tobedecode_byte.Length);
    //calaculates the number of characters produced by decodeing a sequence of bytes from the specified byte array
    char[] decoded_char = newchar[char_Count];
    utf8Decoder.GetChars(tobedecode_byte, 0, tobedecode_byte.Length, decoded_char, 0);
    //Decodes a sequence of bytes from the specified byte array and any butes in the internal buffer into the specified character array
    string resultstring = new String(decoded_char);
    return resultstring;
}

Comments/Suggestions are invited. Happy coding......!

Comments Post a Comment

lovababu 2/4/2011 (IST) / Reply

thank you so much.

ssss 12/28/2011 (IST) / Reply

nice work

abhishek 2/21/2012 (IST) / Reply

thnks for the code

lenin 2/22/2012 (IST) / Reply

s

ngkumar 2/23/2012 (IST) / Reply

nvjdnnbkb

ngkumar 2/23/2012 (IST) / Reply

gjhhjkl

sachin 2/24/2012 (IST) / Reply

sir i am student i download this code study parpuse

aa 4/7/2012 (IST) / Reply

aaaaaa

gaurav 4/11/2012 (IST) / Reply

need source code

webmaster 4/11/2012 (IST) / Reply

To Gaurav: You can download the source code by registering into the website

krupa 4/23/2012 (IST) / Reply

lokking for social network site source code..

adsa 4/24/2012 (IST) / Reply

yessssssssssssss

sandeep 5/10/2012 (IST) / Reply

hey can u please help me , iam unable to run this code its urgent , ihave to show this project on coming saturday

Nagendra 5/10/2012 (IST) / Reply

is there source available for social networking site using jsp? if it not there or tell me how can we delete a post in home page souce code.

piyush 6/23/2012 (IST) / Reply

good

Animesh 10/6/2012 (IST) / Reply

Need to know the requirement for developing such code ..

raghu 11/10/2012 (IST) / Reply

i want to make a social networking site project using j2ee ,,,,,,pls help me to devlop it

rabaa 1/27/2013 (IST) / Reply

hello

swapnil Agarwal 1/28/2013 (IST) / Reply

thnxs

chitti 1/29/2013 (IST) / Reply

It is very nice yaaa.....:) thnk you so much.....:) :)

juliusangel 2/2/2013 (IST) / Reply

i want to rank my site to top most site

shailendra 2/9/2013 (IST) / Reply

I shailendra kalmegh wanted a java project

rama 4/12/2013 (IST) / Reply

I Want to develop same in j2ee. can you pls send me the code..

Rubal Chandra Das 6/23/2013 (IST) / Reply

plz me project a project on social networking site using j2ee at rubelk.das7@gmail.com

ashish 8/12/2013 (IST) / Reply

plz send me the code of social networking site......thanxx in advance

Nic 10/19/2013 (IST) / Reply

I dont understand the instructions

Harsha 1/26/2014 (IST) / Reply

I am willing to Develop an Social Network site, help me!!

Sergio BrAZIL 2/7/2014 (IST) / Reply

Tanks.....alll...succes for alll brothers!!!!

asheesh 7/25/2014 (IST) / Reply

good

Abhishek 11/24/2014 (IST) / Reply

sir i am student i download this code study parpuse

vivekmp 2/6/2015 (IST) / Reply

plz send me code and doc

swedha 11/29/2015 (IST) / Reply

send me coding to create social networking websites for my project

prasanth 6/27/2016 (IST) / Reply

hello sir