TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
alok Chaudhary
NA
6
783
how can we encrypt and decrypt username and password
Dec 1 2017 5:25 AM
if (!IsPostBack)
{
base.Page_Load(sender, e);
FillAllRole();
if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null)
{
txtUsername.Value = Request.Cookies["UserName"].Value;
txtPassword.Attributes.Add("value", Request.Cookies["Password"].Value);
chkRememberMe.Checked = true;
btnSubmit.Focus();
}
else
{
txtUsername.Value = String.Empty;
txtPassword.Text = String.Empty;
txtPassword.Attributes.Add("placeholder", "Password");
chkRememberMe.Checked = false;
txtUsername.Focus();
}
}
}
protected void BtnSubmit_ServerClick(object sender, EventArgs e)
{
try
{
btnSubmit.Disabled = true;
string userName = txtUsername.Value;
ViewState["userPassword"] = txtPassword.Text;
var objService = ServiceFactory.CreateSecurityService();
var validateUser = objService.IsValidUser(userName, ViewState["userPassword"].ToString(), String.Concat(ConfigurationManager.AppSettings["ADBaseDirectory"], ConfigurationManager.AppSettings["ADPath"]));
// var DefaultRole = objService.IsDefaultRoleMarked(userName);
if (validateUser.Item1 && validateUser.Item2 && validateUser.Item3 != Guid.Empty)
{
RememberMe(userName, ViewState["userPassword"].ToString());
//Response.Redirect("HomePage.aspx?LandingModuleID=" + CustomCryptoServiceProvider.Encrypt(validateUser.Item3.ToString()), false);
Response.Redirect(RedirectionFactory.GetPageName(validateUser.Item3), false);
}
else if (validateUser.Item1 && !validateUser.Item2)
{
foreach (var item in CustomAuthentication.GetUserRoleCollection())
ddlFirstTime.Items.Add(new ListItem(item.RoleName, (Convert.ToString(item.RoleID))));
txtUsername.Disabled = true;
txtPassword.Enabled = false;
lblFirstTime.Visible = true;
ddlFirstTime.Visible = true;
errorMsg.Visible = false;
imgbtnProceed.Visible = true;
btnSubmit.Visible = false;
lbRegister.Visible = false;
lblRememberMe.Visible = false;
chkRememberMe.Visible = false;
}
else if (!validateUser.Item1 && !validateUser.Item2)
{
errorMsg.Visible = true;
errorMsg.Text = Nihilent.PMOTracker.Common.Resource.ErrorMsgLogin;
btnSubmit.Disabled = false;
lblFirstTime.Visible = false;
ddlFirstTime.Visible = false;
imgbtnProceed.Visible = false;
}
}
catch (Exception ex)
{
btnSubmit.Disabled = false;
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
}
private void RememberMe(string userName, string userPassword)
{
if (chkRememberMe.Checked)
{
Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30);
Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
}
else
{
Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
}
Response.Cookies["UserName"].Value = userName;
Response.Cookies["Password"].Value = userPassword;
}
Reply
Answers (
1
)
Instead of for Loop , i would like to written in LINQ
how to get data using ajax