Exemplo n.º 1
0
 /// <summary>
 /// Used for sending email
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnSendMail_Click(object sender, EventArgs e)
 {
     try
     {
         if (!string.IsNullOrEmpty(txtEmail.Text.Trim()))
         {
             objUser = objUserBLL.GetUserDetailsByEmailId(txtEmail.Text.Trim());
             if (objUser != null)
             {
                 if (objUser.Id != 0)
                 {
                     if (objUser.IsEmailVerified == true)
                     {
                         SendForgetPassword(objUser.Id, objUser.FirstName, objUser.LastName, objUser.UserLogin.UserName);
                     }
                     else
                     {
                         lblErrorMsg.Text = "Email address is not verified, Please click the link sent to your registered email address.";
                     }
                 }
                 else
                 {
                     lblErrorMsg.Text = "No account found with that email address.";
                 }
             }
             else
             {
                 lblErrorMsg.Text = "No account found with that email address.";
             }
         }
     }
     catch (Exception ex)
     {
         log.Error("btnSendMail_Click \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
         ExceptionLog.WriteLog(PageName + " @ btnSendMail_Click ", ex.Message + " \n " + ex.StackTrace);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                // Active Directory selected
                if (rdolstAuthenticationType.SelectedValue == "0")
                {
                    Dns.GetHostName();
                    ExceptionLog.WriteLog(PageName + " @ HttpContext.Current.User.Identity.Name ", HttpContext.Current.User.Identity.Name + " \n ");
                    ExceptionLog.WriteLog(PageName + " @  Dns.GetHostName()", Dns.GetHostName() + " \n ");
                    ExceptionLog.WriteLog(PageName + " @  Dns.GetHostEntry(Request.ServerVariables[]).HostName", Dns.GetHostEntry(Dns.GetHostName()).HostName + " \n ");
                    ExceptionLog.WriteLog(PageName + " @  System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName", System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName + " \n ");
                    if (DoesUserExist(System.Security.Principal.WindowsIdentity.GetCurrent().Name))
                    {
                        objLoginHistory.UserId = Convert.ToInt32(Session["UserId"]);
                        objLoginHistory.LoginTime = DateTime.Now;
                        objLoginHistory.CreatedBy = Convert.ToInt32(Session["UserId"]);
                        objLoginHistory.CreatedOn = DateTime.Now;
                        objLoginHistory.CreatedIp = CommonUtils.GetIPAddresses();
                        objLoginHistory.UserName = Environment.UserName;
                        objUserBLL.LogLoginTime(objLoginHistory);

                        Session["UserName"] = Environment.UserName;
                        Response.Redirect("LoginLogoutHistory.aspx");
                    }
                    else
                    {
                        lblError.Text = "No account found with that username.";
                        lblError.Attributes.Add("display", "block");
                        txtUserName.Text = string.Empty;
                        txtPassword.Text = string.Empty;
                    }
                }
                else if (rdolstAuthenticationType.SelectedValue == "1")
                {
                    if (!string.IsNullOrEmpty(txtUserName.Text.Trim()) && !string.IsNullOrEmpty(txtPassword.Text.Trim()))
                    {
                        //SQL Server Validation
                        objUser = objUserBLL.GetUserDetailsByUserName(txtUserName.Text.Trim());
                        if (objUser != null)
                        {
                            if (objUser.Id != 0 && objUser.UserLogin.IsActive == true)
                            {
                                if (objUser.UserLogin.AccountLocked == true)
                                {
                                    lblError.Text = "The account is locked please contact administrator.";
                                    lblError.Attributes.Add("display", "block");
                                    txtUserName.Text = string.Empty;
                                    txtPassword.Text = string.Empty;
                                }
                                else
                                {
                                    if (objUser.UserLogin.Password.Equals(CommonUtils.Encrypt(txtPassword.Text.Trim())))
                                    {
                                        Session["RoleId"] = Convert.ToString(objUser.UserLogin.RoleId);
                                        Session["UserId"] = Convert.ToString(objUser.Id);
                                        objLoginHistory.UserId = objUser.Id;
                                        objLoginHistory.LoginTime = DateTime.Now;
                                        objLoginHistory.CreatedBy = Convert.ToInt32(Session["UserId"]);
                                        objLoginHistory.CreatedOn = DateTime.Now;
                                        objLoginHistory.CreatedIp = CommonUtils.GetIPAddresses();
                                        objLoginHistory.UserName = objUser.UserLogin.UserName;
                                        objUserBLL.LogLoginTime(objLoginHistory);
                                        objUserBLL.ClearLoginAttempts(objUser.Id);

                                        if (chkRememberPassword.Checked == true)
                                        {
                                            Response.Cookies["UserName"].Value = txtUserName.Text;
                                            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(10);
                                            Response.Cookies["Password"].Value = txtPassword.Text;
                                            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(10);
                                        }
                                        else
                                        {
                                            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
                                            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                                        }
                                        Response.Redirect("LoginLogoutHistory.aspx");
                                    }
                                    else
                                    {
                                        objLoginAttempts = objUserBLL.GetLoginAttempts();
                                        if (objLoginAttempts != null && objLoginAttempts.Id > 0)
                                        {
                                            if (objLoginAttempts.LoginAttempt > objUser.UserLogin.PasswordWrongAttempts)
                                            {
                                                if (objLoginAttempts.LoginAttempt == objUser.UserLogin.PasswordWrongAttempts + 1)
                                                {
                                                    objUserLogin.AccountLocked = true;
                                                    objUserLogin.PasswordWrongAttempts = objUser.UserLogin.PasswordWrongAttempts + 1;
                                                    objUserLogin.UpdatedBy = Convert.ToInt32(Session["UserId"]);
                                                    objUserLogin.UpdatedOn = DateTime.Now;
                                                    objUserLogin.LastPasswordWrong = DateTime.Now;
                                                    objUserLogin.UserId = objUser.Id;
                                                    objUserBLL.LockUserDetails(objUserLogin);
                                                }
                                                else
                                                {
                                                    objUserLogin.AccountLocked = false;
                                                    objUserLogin.PasswordWrongAttempts = objUser.UserLogin.PasswordWrongAttempts + 1;
                                                    objUserLogin.UpdatedBy = Convert.ToInt32(Session["UserId"]);
                                                    objUserLogin.UpdatedOn = DateTime.Now;
                                                    objUserLogin.LastPasswordWrong = DateTime.Now;
                                                    objUserLogin.UserId = objUser.Id;
                                                    objUserBLL.UpdatePasswordWorngAttemptDetails(objUserLogin);

                                                    lblError.Text = "Please enter correct User name and password Your access will be locked after " + (objLoginAttempts.LoginAttempt - (objUser.UserLogin.PasswordWrongAttempts + 1)) + " consecutive wrong attempts.";
                                                    lblError.Attributes.Add("display", "block");
                                                    txtUserName.Text = string.Empty;
                                                    txtPassword.Text = string.Empty;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            lblError.Text = "The username or password you entered is incorrect.";
                                            lblError.Attributes.Add("display", "block");
                                            txtUserName.Text = string.Empty;
                                            txtPassword.Text = string.Empty;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                lblError.Text = "No account found with that username.";
                                lblError.Attributes.Add("display", "block");
                                txtUserName.Text = string.Empty;
                                txtPassword.Text = string.Empty;
                            }
                        }
                        else
                        {
                            lblError.Text = "No account found with that username.";
                            lblError.Attributes.Add("display", "block");
                            txtUserName.Text = string.Empty;
                            txtPassword.Text = string.Empty;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("btnLogin_Click \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(PageName + " @ btnLogin_Click ", ex.Message + " \n " + ex.StackTrace);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///  Method for add Userdetails
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public int AddUserDetails(User user)
 {
     return objUserDAL.AddUserDetails(user);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Method for updating Userdetails
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool UpdateUserDetails(User user)
 {
     return objUserDAL.UpdateUserDetails(user);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Method for upadting user details 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool UpdateUserDetails(User user)
        {
            bool result = false;
            try
            {

            }
            catch (Exception ex)
            {
            }
            return result;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Method for inserting user details by userid
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int AddUserDetails(User user)
        {
            int result = 0;
            try
            {
                SqlCommand objSqlCommand = new SqlCommand();

                SqlParameter[] objLstParams = new SqlParameter[20];

                SqlParameter objFirstName = new SqlParameter("@FirstName", SqlDbType.VarChar);
                objFirstName.Value = user.FirstName;
                objLstParams[0] = objFirstName;

                SqlParameter objLastName = new SqlParameter("@LastName", SqlDbType.VarChar);
                objLastName.Value = user.LastName;
                objLstParams[1] = objLastName;

                SqlParameter objMobile = new SqlParameter("@Mobile", SqlDbType.VarChar);
                objMobile.Value = user.Mobile;
                objLstParams[2] = objMobile;

                SqlParameter objEmail = new SqlParameter("@Email", SqlDbType.VarChar);
                objEmail.Value = user.Email;
                objLstParams[3] = objEmail;

                SqlParameter objGender = new SqlParameter("@Gender", SqlDbType.Int);
                objGender.Value = user.Gender;
                objLstParams[4] = objGender;

                SqlParameter objAddress = new SqlParameter("@Address", SqlDbType.VarChar);
                objAddress.Value = user.Address;
                objLstParams[5] = objAddress;

                SqlParameter objCountryId = new SqlParameter("@CountryId", SqlDbType.Int);
                objCountryId.Value = user.CountryId;
                objLstParams[6] = objCountryId;

                SqlParameter objCity = new SqlParameter("@City", SqlDbType.VarChar);
                objCity.Value = user.City;
                objLstParams[7] = objCity;

                SqlParameter objZipCode = new SqlParameter("@ZipCode", SqlDbType.VarChar);
                objZipCode.Value = user.ZipCode;
                objLstParams[8] = objZipCode;

                SqlParameter objCreatedBy = new SqlParameter("@CreatedBy", SqlDbType.Int);
                objCreatedBy.Value = user.CreatedBy;
                objLstParams[9] = objCreatedBy;

                SqlParameter objCreatedOn = new SqlParameter("@CreatedOn", SqlDbType.DateTime);
                objCreatedOn.Value = user.CreatedOn;
                objLstParams[10] = objCreatedOn;

                SqlParameter objUpdatedBy = new SqlParameter("@UpdatedBy", SqlDbType.Int);
                objUpdatedBy.Value = user.UpdatedBy;
                objLstParams[11] = objUpdatedBy;

                SqlParameter objUpdatedOn = new SqlParameter("@UpdatedOn", SqlDbType.DateTime);
                objUpdatedOn.Value = user.UpdatedOn;
                objLstParams[12] = objUpdatedOn;

                SqlParameter objIsEmailVerified = new SqlParameter("@IsEmailVerified", SqlDbType.Bit);
                objIsEmailVerified.Value = user.IsEmailVerified;
                objLstParams[13] = objIsEmailVerified;

                SqlParameter objUserName = new SqlParameter("@UserName", SqlDbType.VarChar);
                objUserName.Value = user.UserLogin.UserName;
                objLstParams[14] = objUserName;

                SqlParameter objPassword = new SqlParameter("@Password", SqlDbType.VarChar);
                objPassword.Value = user.UserLogin.Password;
                objLstParams[15] = objPassword;

                SqlParameter objSecurityQuestion = new SqlParameter("@SecurityQuestion", SqlDbType.Int);
                objSecurityQuestion.Value = user.UserLogin.SecurityQuestion;
                objLstParams[16] = objSecurityQuestion;

                SqlParameter objAnswer = new SqlParameter("@Answer", SqlDbType.VarChar);
                objAnswer.Value = user.UserLogin.Answer;
                objLstParams[17] = objAnswer;

                SqlParameter objRoleId = new SqlParameter("@RoleId", SqlDbType.Int);
                objRoleId.Value = user.UserLogin.RoleId;
                objLstParams[18] = objRoleId;

                SqlParameter objIsActive = new SqlParameter("@IsActive", SqlDbType.Bit);
                objIsActive.Value = user.UserLogin.IsActive;
                objLstParams[19] = objIsActive;

                result = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.StoredProcedure, SP_AddUserDetails, objLstParams));
                objSqlCommand.Parameters.Clear();
            }
            catch (Exception ex)
            {
                log.Error("AddUserDetails \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(COMMONDATA + " @ AddUserDetails ", ex.Message + " \n " + ex.StackTrace);
            }
            return result;
        }
Exemplo n.º 7
0
        /// <summary>
        ///  Method for getting user details by username
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public User GetUserDetailsByUserName(string userName)
        {
            User objUser = new User();
            UserLogin objUserLogin = new UserLogin();
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.StoredProcedure, SP_GetUserDetailsByUserName, new SqlParameter("@UserName", userName)))
                {
                    if (reader.Read())
                    {
                        objUser.Id = Convert.ToInt32(reader["UserId"]);
                        objUser.FirstName = Convert.ToString(reader["FirstName"]);
                        objUser.LastName = Convert.ToString(reader["LastName"]);
                        objUser.Mobile = Convert.ToString(reader["Mobile"]);
                        objUser.Gender = Convert.ToInt32(reader["Gender"]);
                        objUser.Address = Convert.ToString(reader["Address"]);
                        objUser.CountryId = Convert.ToInt32(reader["CountryId"]);
                        objUser.City = Convert.ToString(reader["City"]);
                        objUser.ZipCode = Convert.ToString(reader["ZipCode"]);
                        objUser.CreatedBy = Convert.ToInt32(reader["CreatedBy"]);
                        objUser.CreatedOn = Convert.ToDateTime(reader["CreatedOn"]);
                        objUser.UpdatedBy = Convert.ToInt32(reader["UpdatedBy"]);
                        objUser.UpdatedOn = Convert.ToDateTime(reader["UpdatedOn"]);
                        objUser.IsEmailVerified = Convert.ToBoolean(reader["IsEmailVerified"]);
                        objUserLogin.UserName = Convert.ToString(reader["UserName"]);
                        objUserLogin.Password = Convert.ToString(reader["Password"]);
                        objUserLogin.SecurityQuestion = Convert.ToInt32(reader["SecurityQuestion"]);
                        objUserLogin.Answer = Convert.ToString(reader["Answer"]);
                        objUserLogin.PasswordWrongAttempts = Convert.ToInt32(reader["PasswordWrongAttempts"]);
                        if (!string.IsNullOrWhiteSpace(Convert.ToString(reader["LastPasswordWrong"])))
                        {
                            objUserLogin.LastPasswordWrong = Convert.ToDateTime(reader["LastPasswordWrong"]);
                        }
                        else
                        {
                            objUserLogin.LastPasswordWrong = null;
                        }

                        objUserLogin.RoleId = Convert.ToInt32(reader["RoleId"]);
                        objUserLogin.IsActive = Convert.ToBoolean(reader["IsActive"]);
                        objUserLogin.UserId = Convert.ToInt32(reader["UserId"]);
                        if (!string.IsNullOrWhiteSpace(Convert.ToString(reader["AccountLocked"])))
                        {
                            objUserLogin.AccountLocked = Convert.ToBoolean(reader["AccountLocked"]);
                        }
                        else
                        {
                            objUserLogin.AccountLocked = false;
                        }
                        objUser.UserLogin = objUserLogin;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("GetUserDetailsByUserName \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(COMMONDATA + " @ GetUserDetailsByUserName ", ex.Message + " \n " + ex.StackTrace);
            }
            return objUser;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Method for getting user details 
        /// </summary>
        /// <returns></returns>
        public List<User> GetUserDetails()
        {
            List<User> objLstUser = new List<User>();
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                using (DataSet objUserDataSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, CommandType.StoredProcedure, SP_GetUserDetails))
                {
                    if (objUserDataSet.Tables[0].Rows.Count > 0)
                    {

                        for (int i = 0; i < objUserDataSet.Tables[0].Rows.Count; i++)
                        {
                            User objUser = new User();
                            UserLogin objUserLogin = new UserLogin();

                            objUser.Id = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["UserId"]);
                            objUser.FirstName = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["FirstName"]);
                            objUser.LastName = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["LastName"]);
                            objUser.Mobile = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["Mobile"]);
                            objUser.Gender = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["Gender"]);
                            objUser.Address = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["Address"]);
                            objUser.CountryId = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["CountryId"]);
                            objUser.Email = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["Email"]);
                            objUser.City = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["City"]);
                            objUser.ZipCode = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["ZipCode"]);
                            objUser.CreatedBy = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["CreatedBy"]);
                            objUser.CreatedOn = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["CreatedOn"]);
                            objUser.UpdatedBy = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["UpdatedBy"]);
                            objUser.UpdatedOn = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["UpdatedOn"]);
                            objUser.IsEmailVerified = Convert.ToBoolean(objUserDataSet.Tables[0].Rows[i]["IsEmailVerified"]);
                            objUserLogin.UserName = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["UserName"]);
                            objUserLogin.Password = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["Password"]);
                            objUserLogin.SecurityQuestion = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["SecurityQuestion"]);
                            objUserLogin.Answer = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["Answer"]);
                            objUserLogin.PasswordWrongAttempts = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["PasswordWrongAttempts"]);
                            if (!string.IsNullOrWhiteSpace(Convert.ToString(objUserDataSet.Tables[0].Rows[i]["LastPasswordWrong"])))
                            {
                                objUserLogin.LastPasswordWrong = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["LastPasswordWrong"]);
                            }
                            else
                            {
                                objUserLogin.LastPasswordWrong = null;
                            }
                            objUserLogin.CreatedBy = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["CreatedBy"]);
                            objUserLogin.CreatedOn = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["CreatedOn"]);
                            objUserLogin.UpdatedBy = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["UpdatedBy"]);
                            objUserLogin.UpdatedOn = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["UpdatedOn"]);
                            objUserLogin.RoleId = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["RoleId"]);
                            objUserLogin.IsActive = Convert.ToBoolean(objUserDataSet.Tables[0].Rows[i]["IsActive"]);
                            objUserLogin.UserId = Convert.ToInt32(objUserDataSet.Tables[0].Rows[i]["UserId"]);
                            if (!string.IsNullOrWhiteSpace(Convert.ToString(objUserDataSet.Tables[0].Rows[i]["AccountLocked"])))
                            {
                                objUserLogin.AccountLocked = Convert.ToBoolean(objUserDataSet.Tables[0].Rows[i]["AccountLocked"]);
                            }
                            else
                            {
                                objUserLogin.AccountLocked = false;
                            }
                            objUser.UserLogin = objUserLogin;
                            objLstUser.Add(objUser);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("GetUserDetails \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(COMMONDATA + " @ GetUserDetails ", ex.Message + " \n " + ex.StackTrace);
            }
            return objLstUser;
        }