public string RecoverPassword(string username) { MembershipUser mu = Membership.GetUser(username); string MsgOut = string.Empty; if (mu != null) { if (mu.IsLockedOut) { MsgOut = "Your Account is locked. Please go back and use unlock account link"; } else { CommonClass objCommonClass = new CommonClass(); string TypeCode = objCommonClass.GetUserType(mu.UserName); if (TypeCode != "CG") { ArrayList arMail = new ArrayList(); arMail = objCommonClass.Getmail(mu.UserName); string strBody = ""; strBody += "Dear <b>" + arMail[3].ToString() + "</b>,<br/><br/>Please find your login credentials below:<br/>"; //strBody += " User Name: " + strUserName + "<br/>"; strBody += " Password: "******"<br/>"; strBody += " CG Care,<br/>"; SqlParameter[] sqlParam = { new SqlParameter("@Email", arMail[1].ToString()), new SqlParameter("@body", strBody) }; int suc = ObjSql.ExecuteNonQuery(CommandType.StoredProcedure, "uspSendMailForPassword", sqlParam); // objCommonClass.SendMailSMTP(arMail[1].ToString().Trim(), ConfigurationManager.AppSettings["FromMailId"].ToString(), "Login Details", strBody, true); MsgOut = string.Empty; } else { MsgOut = "CG Employees cannot unlock their account from this Page. Contact CG hr4u Team."; } } } else { MsgOut = "Invalid User Id"; } return(MsgOut); }
public void UnlockUserAccount() { string Message = string.Empty; this.ObjMembershipUser = Membership.GetUser(this.LoginName); if (this.ObjMembershipUser == null) { this.Message = "Invalid UserID"; } else if (!this.ObjMembershipUser.IsLockedOut) { this.Message = "Your Account is alreday unlocked."; } else { try { String NewPwd = DateTime.Now.Ticks.ToString(); this.ObjMembershipUser.UnlockUser(); string newP = BPSecurity.ProtectPassword(NewPwd); if (this.ObjMembershipUser.ChangePassword(this.ObjMembershipUser.GetPassword(), newP)) { Membership.UpdateUser(this.ObjMembershipUser); // UpdatePasswordHisortLog(this.ObjMembershipUser.UserName, newP , "Password unlocked and Reset"); } //string strBody = ""; //strBody += "Dear <b>" + this.ObjMembershipUser.UserName + "</b>,<br/><br/>Your Account has been unlocked Successfully. Please find your login credentials below:<br/>"; //strBody += " User Name: " + this.ObjMembershipUser.UserName + "<br/>"; //strBody += " Password: "******"<br/>"; //strBody += " CG Care,<br/>"; //objCommonClass.SendMailSMTP(this.ObjMembershipUser.Email, ConfigurationManager.AppSettings["FromMailId"].ToString(), "Account Unlocked.", strBody, true); this.Message = ""; } catch (Exception ex) { this.Message = ex.Message; } } }
void UpdatePasswordHisortLog(string userName, string newPassword, string Remarks) { SqlParameter[] sqlParamSrh = { new SqlParameter("@MessageOut", SqlDbType.VarChar, 200), new SqlParameter("@Return_Value", SqlDbType.Int), new SqlParameter("@Type", "LOG_PASSWORD_HISTORY"), new SqlParameter("@UserName", userName), new SqlParameter("@Password", newPassword), new SqlParameter("@DecPassword", BPSecurity.UnprotectPassword(newPassword)), new SqlParameter("@SpecialRemarks", Remarks), new SqlParameter("@SystemIP", this.IPAddress) }; sqlParamSrh[0].Direction = ParameterDirection.Output; sqlParamSrh[1].Direction = ParameterDirection.ReturnValue; ObjSql.ExecuteNonQuery(CommandType.StoredProcedure, "uspEditUserAndRoleMaster", sqlParamSrh); //ReturnValue = int.Parse(sqlParamSrh[1].Value.ToString()); if (int.Parse(sqlParamSrh[1].Value.ToString()) == -1) { this.Message = sqlParamSrh[0].Value.ToString(); } }
public string ChangePassword(string oldPassword, string newPassword, string Remarks) // Last update 27-9-13 { MembershipUser mUser = Membership.GetUser(); string StrMsg = string.Empty; if (mUser == null) { StrMsg = "You are not a valid user"; } //else if (mUser.LastPasswordChangedDate.AddDays(1) > DateTime.Today) // StrMsg = "You cannot change the password on the same day"; else { // Change 27-9-13 bool IsSCRole = HttpContext.Current.User.IsInRole("SC"); string Pwd = mUser.GetPassword(); if (IsSCRole) { if (BPSecurity.ProtectPassword(oldPassword) == Pwd) { if (IsPasswordMatchWithLast4(mUser.UserName, BPSecurity.ProtectPassword(newPassword))) { StrMsg = "Your Password matches with your Last 4 passwords. Please choose different password."; } else if (mUser.ChangePassword(Pwd, BPSecurity.ProtectPassword(newPassword))) { UpdatePasswordHisortLog(mUser.UserName, BPSecurity.ProtectPassword(newPassword), Remarks); StrMsg = ""; } else { StrMsg = "Error !!"; } } else { StrMsg = "Wrong old Password ."; } } else // Added 27-9-13 for other Roles then SC { if (oldPassword == Pwd) { if (mUser.ChangePassword(Pwd, newPassword)) { StrMsg = ""; } else { StrMsg = "Error !!"; } } else { StrMsg = "Wrong oldPassword ."; } } } return(StrMsg); }
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { Label lblLoginErrors = (Label)Login1.FindControl("lblLoginErrors"); DataSet dsUser = new DataSet(); SqlDataAccessLayer objSql = new SqlDataAccessLayer(); string usertype; SqlParameter[] sqlParam = { new SqlParameter("@Type", "SELECT_USER_BY_USRNAME"), new SqlParameter("@UserName", Login1.UserName) }; dsUser = objSql.ExecuteDataset(CommandType.StoredProcedure, "uspEditUserAndRoleMaster", sqlParam); if (dsUser.Tables[0].Rows.Count == 0) { e.Authenticated = false; } else { usertype = Convert.ToString(dsUser.Tables[0].Rows[0]["UserType_Code"]); Session["UserType_Code"] = usertype; if (usertype == "CG") { //***********Live Before Change By Priyam************************//////// //CGEncription.CGEncription objEncriptStr = new CGEncription.CGEncription(); //CGWebService1.CGWebService objCGWebservice = new CGWebService1.CGWebService(); //if (!objCGWebservice.EncrGetData(Login1.UserName.ToString().Trim(), objEncriptStr.getEncrValue(Login1.Password.ToString().Trim())).Equals("OK", StringComparison.CurrentCultureIgnoreCase)) //{ // e.Authenticated = false; // objEncriptStr = null; // objCGWebservice = null; // lblLoginErrors.Text = "Invalid User Id or Password."; //} //else //{ // objEncriptStr = null; // objCGWebservice = null; // e.Authenticated = true; //} ////*********** //e.Authenticated = true; /////////////********************Live End//////////////////////// //***********Updated after Change************************//////// if (Membership.ValidateUser(Login1.UserName, BPSecurity.ProtectPassword(Login1.Password.Trim())) == false) { e.Authenticated = false; lblLoginErrors.Text = "Invalid User Id or Password."; } else { e.Authenticated = true; if (!Membership.GetUser(Login1.UserName).IsOnline) { e.Authenticated = true; } else { lblLoginErrors.Text = "You are currently loggin In."; } } //***********Update Change End************************//////// } else if (usertype == "SC") { if (Membership.ValidateUser(Login1.UserName, BPSecurity.ProtectPassword(Login1.Password.Trim())) == false) { e.Authenticated = false; lblLoginErrors.Text = "Invalid User Id or Password."; // e.Authenticated = true; } else { e.Authenticated = true; if (!Membership.GetUser(Login1.UserName).IsOnline) { e.Authenticated = true; } else { lblLoginErrors.Text = "You are currently loggin In."; } } } else if (usertype != "WSCC") { if (Membership.ValidateUser(Login1.UserName, Login1.Password.Trim()) == false) { e.Authenticated = false; lblLoginErrors.Text = "Invalid User Id or Password."; } else { e.Authenticated = true; } } } // Uncomment bellow code for live and replace from above //else //{ // usertype = Convert.ToString(dsUser.Tables[0].Rows[0]["UserType_Code"]); // Session["UserType_Code"] = usertype ; // if (usertype == "CG") // { // //*********** // CGEncription.CGEncription objEncriptStr = new CGEncription.CGEncription(); // CGWebService objCGWebservice = new CGWebService(); // if (!objCGWebservice.EncrGetData(Login1.UserName.ToString().Trim(), objEncriptStr.getEncrValue(Login1.Password.ToString().Trim())).Equals("OK", StringComparison.CurrentCultureIgnoreCase)) // { // e.Authenticated = false; // objEncriptStr = null; // objCGWebservice = null; // lblLoginErrors.Text = "Invalid User Id or Password."; // } // else // { // objEncriptStr = null; // objCGWebservice = null; // e.Authenticated = true; // } // //*********** // //e.Authenticated = true; // } // else if (usertype == "SC") // { // if (Membership.ValidateUser(Login1.UserName, BPSecurity.ProtectPassword(Login1.Password.Trim())) == false) // { // e.Authenticated = false; // lblLoginErrors.Text = "Invalid User Id or Password."; // // e.Authenticated = true; // } // else // { // e.Authenticated = true; // if (!Membership.GetUser(Login1.UserName).IsOnline) // { // e.Authenticated = true; // } // else // { // lblLoginErrors.Text = "You are currently loggin In."; // } // } // } // else if (usertype != "WSCC") // { // if (Membership.ValidateUser(Login1.UserName, Login1.Password.Trim()) == false) // { // e.Authenticated = false; // lblLoginErrors.Text = "Invalid User Id or Password."; // } // else // { // e.Authenticated = true; // } // } //} if (e.Authenticated == true) { string ipaddress; ipaddress = Request.ServerVariables["http_x_forwarded_for"]; if (ipaddress == "" || ipaddress == null) { ipaddress = Request.ServerVariables["remote_addr"]; } SqlParameter[] sqlparameters = { new SqlParameter("@username", Login1.UserName), new SqlParameter("@loginip", ipaddress), new SqlParameter("@type", "insert") }; objSql.ExecuteNonQuery(CommandType.StoredProcedure, "uspasp_logincounter", sqlparameters); sqlparameters = null; } sqlParam = null; }
protected void imgBtnAdd_Click(object sender, EventArgs e) { try { MembershipCreateStatus objMembershipCreateStatus; if (ddlUserType.SelectedItem.Text.ToLower() == "Call Centre Executive".ToLower()) { objUserMaster.TvtUserId = txtTvtUserId.Text; objUserMaster.UserName = ""; if (!objUserMaster.validateTvtUserId()) { lblMessage.Text = "This TVT User Id is allready assigned.Please deactivate that user or enter other TVT User Id"; return; } } bool bolActive; if (rdoStatus.SelectedValue.ToString() == "1") { bolActive = true; } else { bolActive = false; } if (ddlUserType.SelectedItem.Text.ToLower() == "cg") { Membership.CreateUser(txtUsername.Text.Trim(), "cg@123", txtUserEmailId.Text.Trim(), "Question", "Answer", bolActive, out objMembershipCreateStatus); } else if (ddlUserType.SelectedItem.Text.ToLower() == "sc") { Membership.CreateUser(txtUsername.Text.Trim(), BPSecurity.ProtectPassword(txtPassword.Text.Trim()), txtUserEmailId.Text.Trim(), "Question", "Answer", bolActive, out objMembershipCreateStatus); } else { Membership.CreateUser(txtUsername.Text.Trim(), txtPassword.Text.Trim(), txtUserEmailId.Text.Trim(), "Question", "Answer", bolActive, out objMembershipCreateStatus); } if (objMembershipCreateStatus == MembershipCreateStatus.Success) { objUserMaster.Name = txtName.Text.Trim(); objUserMaster.UserType = ddlUserType.SelectedValue.ToString(); objUserMaster.UserName = txtUsername.Text.Trim(); objUserMaster.PasswordExpiryPeriod = 0; objUserMaster.Password = txtPassword.Text.Trim(); objUserMaster.EmailId = txtUserEmailId.Text.Trim(); objUserMaster.TvtUserId = txtTvtUserId.Text.Trim(); if (ddlRegion.SelectedValue == "Select") { objUserMaster.Region = "0"; } else { objUserMaster.Region = ddlRegion.SelectedValue.ToString(); } if (ddlBranch.SelectedValue == "Select") { objUserMaster.Branch = "0"; } else { objUserMaster.Branch = ddlBranch.SelectedValue.ToString(); } if (ddlProductDivision.SelectedValue == "Select") { objUserMaster.unit_sno = "0"; } else { objUserMaster.unit_sno = ddlProductDivision.SelectedValue.ToString(); } objUserMaster.ActiveFlag = rdoStatus.SelectedValue.ToString(); objUserMaster.SaveData("INSERT_USER_MASTER_DATA"); if (objUserMaster.ReturnValue == -1) { // Membership.DeleteUser(txtUsername.Text.Trim()); //Writing Error message to File using CommonClass WriteErrorErrFile method taking arguments as URL of page // trace, error message CommonClass.WriteErrorErrFile(Request.RawUrl.ToString(), objUserMaster.MessageOut); } //Save data for service contractor if (ddlUserType.SelectedItem.Text.ToLower().IndexOf("contractor") != -1) { objUserMaster.Name = txtName.Text.Trim(); objUserMaster.UserName = txtUsername.Text.Trim(); objUserMaster.Address1 = txtAddOne.Text.Trim(); objUserMaster.Address2 = txtAddTwo.Text.Trim(); objUserMaster.ContactPerson = txtContactPerson.Text.Trim(); objUserMaster.PhoneNo = txtPhoneNo.Text.Trim(); objUserMaster.MobileNo = txtMobileNo.Text.Trim(); objUserMaster.Prefernce = txtPrefence.Text.Trim(); objUserMaster.SpecialRemarks = txtSpecialRemarks.Text.Trim(); objUserMaster.FaxNo = txtFaxNo.Text.Trim(); objUserMaster.EmailId = txtUserEmailId.Text.Trim(); objUserMaster.EmpCode = Membership.GetUser().UserName.ToString(); objUserMaster.Weekly_Off_Day = ddlWeeklyOffDay.SelectedValue; objUserMaster.Branch = ddlBranch.SelectedValue.ToString(); objUserMaster.State = ddlState.SelectedValue.ToString(); objUserMaster.City = ddlCity.SelectedValue.ToString(); objUserMaster.SaveDataSC("INSERT_SC_DATA"); if (objUserMaster.ReturnValue == -1) { //Membership.DeleteUser(txtUsername.Text.Trim()); //Writing Error message to File using CommonClass WriteErrorErrFile method taking arguments as URL of page // trace, error message CommonClass.WriteErrorErrFile(Request.RawUrl.ToString(), objUserMaster.MessageOut); } } //Send Mail to user if (ddlUserType.SelectedItem.Text.ToLower() != "cg") { string strBody = ""; if (txtUserEmailId.Text.Trim() != "") { strBody += "Dear <b>" + txtName.Text.Trim() + "</b>,<br/>Your account has been successfully created.<br/>Please find your login credentials below:<br/>"; strBody += " User Id: " + txtUsername.Text.Trim() + "<br/>"; strBody += " Password: "******"<br/>"; strBody += " Thanks,<br/>CG Team"; // objCommonClass.SendMailSMTP(txtUserEmailId.Text.Trim(), ConfigurationManager.AppSettings["FromMailId"].ToString(), "Registration", strBody, true); } } //End lblMessage.Text = CommonClass.getErrorWarrning(enuErrorWarrning.AddRecord, enuMessageType.UserMessage, false, ""); ClearContant(); } else { // Membership.DeleteUser(txtUsername.Text.Trim()); //lblMessage.Text = objMembershipCreateStatus.ToString(); lblMessage.Text = CommonClass.getErrorWarrning(enuErrorWarrning.DulplicateRecord, enuMessageType.UserMessage, true, "User id is already exist."); } imgBtnUpdate.Visible = false; imgBtnAdd.Visible = true; imgBtnCancel.Visible = true; objCommonClass.BindDataGrid(gvShowUser, "uspEditUserAndRoleMaster", true, sqlParamSrh, lblRowCount); } catch (Exception ex) { //Writing Error message to File using CommonClass WriteErrorErrFile method taking arguments as URL of page // trace, error message CommonClass.WriteErrorErrFile(Request.RawUrl.ToString(), ex.StackTrace.ToString() + "-->" + ex.Message.ToString()); } }