Sunday 9 February 2014

How to Encrypt or Decrypt password using Asp.Net with c#



//this function Convert to Encord your Password 
public static string EncodePasswordToBase64(string password) 
{
   try 
   {
      byte[] encData_byte = new byte[password.Length]; 
      encData_byte = System.Text.Encoding.UTF8.GetBytes(password); 
      string encodedData = Convert.ToBase64String(encData_byte); 
      return encodedData; 
   } 
   catch (Exception ex) 
   { 
      throw new Exception("Error in base64Encode" + ex.Message); 
   } 
} //this function Convert to Decord your Password
public string DecodeFrom64(string encodedData) 
{
   System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); 
   System.Text.Decoder utf8Decode = encoder.GetDecoder();
   byte[] todecode_byte = Convert.FromBase64String(encodedData); 
   int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); 
   char[] decoded_char = new char[charCount]; 
   utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); 
   string result = new String(decoded_char); 
   return result;
}
  1. Example Of First Enter Password = "rraannaammeett"

  2. EncodePasswordToBase64 function convert your string and give output  ans= "cnJhYW5uYWFtbWVldHQ="

  3. DecodeFrom64 function convert your strring and give output  ans="rraannaammeett"

Get User Details IP Address, city, country, state, latitude, longitude

Get User Details IP Address, city, country, state, latitude, longitude.


Here I will explain how to get user current location details IP address, country, city, state, latitude and longitude using smart-ip json url in JavaScript using asp.net in C#, VB.NET.
To get current user location details I am using smart-ip.net json string to get all the information for that you need to write the following code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get User Details IP Address, city, country, state, latitude, longitude</title>
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
var strip, strcountry, strcity, strregion, strlatitude, strlongitude, strtimezone
function GetUserInfo(data) {
strip = data.host; strcountry = data.countryName; strcity = data.city;
strregion = data.region; strlatitude = data.latitude; strlongitude = data.longitude;
strtimezone = data.timezone;
}
$(function () {
BindUserInfo();
})
function BindUserInfo() {
document.getElementById('lblIP').innerHTML = strip;
document.getElementById('lblCountry').innerHTML = strcountry;
document.getElementById('lblCity').innerHTML = strcity;
document.getElementById('lblregion').innerHTML = strregion;
document.getElementById('lbllatitude').innerHTML = strlatitude;
document.getElementById('lbllongitude').innerHTML = strlongitude;
document.getElementById('lbltimezone').innerHTML = strtimezone;
}
</script>
<script type="text/javascript" src="http://smart-ip.net/geoip-json?callback=GetUserInfo"></script>
</head>
<body>
<div>
<table id="tbDetails" cellpadding="2" cellspacing="2" style=" border:1px solid #000; font-family:Verdana;" >
<tr style="background-color:#DC5807; color:White; font-weight:bold">
<td colspan="2" align="center">User Information</td>
</tr>
<tr style="border:solid 1px #000000">
<td align="right"><b>IP:</b></td>
<td><label id="lblIP"/></td>
</tr>
<tr>
<td align="right"><b>Country:</b></td>
<td><label id="lblCountry"/></td>
</tr>
<tr>
<td align="right"><b>City:</b></td>
<td><label id="lblCity"/></td>
</tr>
<tr>
<td align="right"><b>Region:</b></td>
<td><label id="lblregion"/></td>
</tr>
<tr>
<td align="right"><b>latitude:</b></td>
<td><label id="lbllatitude"/></td>
</tr>
<tr>
<td align="right"><b>Longitude:</b></td>
<td><label id="lbllongitude"/></td>
</tr>
<tr>
<td align="right"><b>Time Zone:</b></td>
<td><label id="lbltimezone"/></td>
</tr>
</table>
</div>
</body>
</html>