Feeds:
Posts
Comments

Posts Tagged ‘asp net’

encrypt decrypt password asp.net?

encrypt decrypt password asp.net with c#.

Namespace

using System.Text;

private string Encryptdata(string password)
    {
        string strmsg = string.Empty;
        byte[] encode = new byte[password.Length];
        encode = Encoding.UTF8.GetBytes(password);
        strmsg = Convert.ToBase64String(encode);
        return strmsg;
    }

private string Decryptdata(string encryptpwd)
    {
        string decryptpwd = string.Empty;
        UTF8Encoding encodepwd = new UTF8Encoding();
        Decoder Decode = encodepwd.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
        int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
        char[] decoded_char = new char[charCount];
        Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
        decryptpwd = new String(decoded_char);
        return decryptpwd;
    }

string strpassword = Encryptdata(TextBox1.Text); //Enc

string strpassword = Decryptdata(TextBox1.Text); //Dec

Read Full Post »

Dropdown list in asp.net Mvc 3  using Razor

1)Create Model
public class AddCatagory
{
public List<SelectListItem> ParentList { get; set; }
[DisplayName("Parent")]
public int parent { get; set; }
}

2) Controller
public ActionResult AddCatagory(AddCatagory AddModel)
{
AddModel.ParentList = parentListFu("VS");
//AddModel.parent =0 ;
return View(AddModel);// dont pass to forgot model in view
}

// hardcoded function in controller

private List<SelectListItem> parentListFu(string defaultValue)
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "Nagaur", Value = "Na", Selected = (defaultValue == "na") });
items.Add(new SelectListItem { Text = "Thalanju", Value = "Th", Selected = (defaultValue == "th") });

return items;
}

3)View

@model Constellation.Models.BusinessLogic.AddCatagory // include model name view

for Dropdownlist

@Html.DropDownListFor(x => x.parent, Model.ParentList, new { @class = "full-width" })

Read Full Post »