コード例 #1
0
        public int Register(UserModel model)
        {
            int userid = 0;

            if (model.Password == model.ConfirmPassword)
            {
                ICommandPassword password = new PasswordGenerator();
                //User user = AutoMapper.Mapper.Map<UserModel, User>(model);
                User user = new User();
                user.Login        = model.Login;
                user.Name         = model.Name;
                user.Password     = model.Password;
                user.CreationDate = DateTime.Now;

                using (var c = new EntityContext())
                {
                    UsersOperation operation = new UsersOperation();
                    ICryptography  crypto    = new PasswordManager();

                    user.Password = crypto.Encrypt(model.Password);
                    userid        = operation.AddAndGetId(user, c);
                }
            }
            return(userid);
        }
コード例 #2
0
        public void ChangePassword(string userName, string activationCode, string newPassword)
        {
            var user = _repository.Query <User>().FirstOrDefault(u => u.UserName == userName);

            if (user == null)
            {
                throw new Exception("User not found!");
            }

            if (string.IsNullOrEmpty(activationCode) || !activationCode.Equals(user.UserLoginInfo.ActivationCode,
                                                                               StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception("Invalid activation code!");
            }

            if (user.UserLoginInfo.ExpireActivationDate.HasValue &&
                user.UserLoginInfo.ExpireActivationDate.Value < DateTime.Now)
            {
                throw new Exception("Expired activation code!");
            }

            ValidateUser(user);

            user.UserLoginInfo.ActivationCode       = null;
            user.UserLoginInfo.ExpireActivationDate = null;
            user.Password = PasswordManager.Encrypt(user.PasswordFormatType.Id.ToString(CultureInfo.InvariantCulture), newPassword);
            _repository.Update(user);
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "user_id,login,password_hash,salt,firstname,lastname,email,date_created,user_group_id")] Users users)
        {
            users.date_created = DateTime.Now;

            var dynamicSalt  = PasswordManager.GetDynamicSalt();
            var staticSalt   = PasswordManager.GetStaticSalt();
            var passwordHash = PasswordManager.Encrypt(users.password_hash, dynamicSalt, staticSalt);

            users.password_hash = passwordHash;
            users.salt          = dynamicSalt;

            try
            {
                if (ModelState.IsValid)
                {
                    db.Users.Add(users);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DbEntityValidationException e)
            {
                return(RedirectToAction("Index"));
            }

            ViewBag.user_group_id = new SelectList(db.UserGroups, "user_group_id", "descr", users.user_group_id);
            return(View(users));
        }
コード例 #4
0
        public UserInformation CheckUserLogin(string UserEmail, string UserPassword)
        {
            UserInformation user = new UserInformation();

            try
            {
                accessManager.SqlConnectionOpen(DataBase.SQQeye);
                List <SqlParameter> aParameters = new List <SqlParameter>();
                aParameters.Add(new SqlParameter("@userName", UserEmail));
                aParameters.Add(new SqlParameter("@userPassword", PasswordManager.Encrypt(UserPassword)));
                SqlDataReader dr = accessManager.GetSqlDataReader("sp_CheckUserLogin", aParameters);
                while (dr.Read())
                {
                    user.UserInformationId    = (int)dr["UserId"];
                    user.UserInformationName  = dr["UserName"].ToString();
                    user.UserInformationEmail = dr["UserEmail"].ToString();
                    user.DesignationId        = (int)dr["DesignationID"];
                    //user.UserInformationPhoneNumber = (int)dr["UserPhone"];
                }

                return(user);
            }
            catch (Exception e)
            {
                accessManager.SqlConnectionClose(true);
                throw;
            }
            finally
            {
                accessManager.SqlConnectionClose();
            }
        }
コード例 #5
0
        public async Task <ApiResponse <UserOld> > FindUser(UserOld user)
        {
            var response       = new ApiResponse <UserOld>();
            var passwordManger = new PasswordManager();

            try
            {
                string password = passwordManger.Encrypt(user.Password);
                var    userRes  = await _usersRepository.FindAsync(i => i.UserName == user.UserName && i.Password == password);

                if (userRes == null)
                {
                    response.Success = true;
                    response.Errors.Add("invalid User");
                    return(response);
                }

                response.Success = true;
                response.Data    = userRes;
                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex.Message);
                return(response);
            }
        }
コード例 #6
0
        public bool SAveUsersToDataBase(UserInformation users)
        {
            bool result = true;

            try
            {
                accessManager.SqlConnectionOpen(DataBase.SQQeye);
                List <SqlParameter> aParameters = new List <SqlParameter>();
                aParameters.Add(new SqlParameter("@userName", users.UserInformationName));
                aParameters.Add(new SqlParameter("@userEmail", users.UserInformationEmail));
                aParameters.Add(new SqlParameter("@userPassword", PasswordManager.Encrypt(users.UserInformationPassword)));
                aParameters.Add(new SqlParameter("@userPhoneNumber", users.UserInformationPhoneNumber));
                aParameters.Add(new SqlParameter("@userType", (int)users.UserTypeId));
                aParameters.Add(new SqlParameter("@createBY", 1));
                aParameters.Add(new SqlParameter("@SqIdNumber", users.UserSQNumber));
                aParameters.Add(new SqlParameter("@DesignationID", (int)users.DesignationId));
                aParameters.Add(new SqlParameter("@BusinessUnitId", (int)users.BusinessUnitId));
                result = accessManager.SaveData("sp_SaveUserInformation", aParameters);
                return(result);
            }
            catch (Exception e)
            {
                accessManager.SqlConnectionClose(true);
                throw e;
            }
            finally
            {
                accessManager.SqlConnectionClose();
            }
        }
コード例 #7
0
        public IActionResult Register(User user)
        {
            if (user.NotNull() && DataProvider.CanCreateUser(user).Result)
            {
                PasswordManager.SetKeys(user.Password, user.Name);
                user.Password = PasswordManager.Encrypt(user.Password);
                PasswordManager.SetKeys("", "");
                user.SaveAsync();

                return(View("Index"));
            }
            return(View("WrongInfo"));
        }
コード例 #8
0
 public ActionResult UpdateUserInformation(UpdateModel usr)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser user   = context2.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);
         UserInformation Update = context.UsersInformation.FirstOrDefault(x => x.Email == user.Email);
         Update.FirstName      = usr.FirstName;
         Update.LastName       = usr.LastName;
         Update.Email          = usr.Email;
         Update.PasswordEmail  = PasswordManager.Encrypt(usr.PasswordEmail);
         Update.CorporateEmail = usr.CorporateEmail;
         context.SaveChanges();
         user.Email = usr.Email;
         context2.SaveChanges();
     }
     return(RedirectToAction("Default", "Users"));
 }
コード例 #9
0
        public IActionResult Index(User user)
        {
            try
            {
                LoginUser = DataProvider.GetUserByEmail(user.Email).Result[0];
                PasswordManager.SetKeys(user.Password, LoginUser.Name);
                string hash = PasswordManager.Encrypt(user.Password);
                if (LoginUser.Password == hash)
                {
                    PasswordManager.SetKeys("", "");
                    //match!
                    return(View("AfterLogin", LoginUser));
                }
                else
                {
                    return(View("WrongEmailOrPassword"));
                }
            }
            catch { }

            return(View("WrongEmailOrPassword"));
        }
コード例 #10
0
        public bool changePassword(int userId, string newpass)
        {
            bool success = false;

            try
            {
                accessManager.SqlConnectionOpen(DataBase.SQQeye);
                List <SqlParameter> aParameters = new List <SqlParameter>();
                aParameters.Add(new SqlParameter("@userId", userId));
                aParameters.Add(new SqlParameter("@newPass", PasswordManager.Encrypt(newpass)));
                success = accessManager.UpdateData("sp_changePassword", aParameters);
                return(success);
            }
            catch (Exception e)
            {
                accessManager.SqlConnectionClose(true);
                throw e;
            }
            finally
            {
                accessManager.SqlConnectionClose();
            }
        }
コード例 #11
0
        public async Task <ApiResponse <UserOld> > CreateUser(UserOldDto userDto)
        {
            var response = new ApiResponse <UserOld>();


            try
            {
                //check user Exists
                var isExistUser = await _usersRepository.CountAsync(i => i.UserName == userDto.UserName);

                if (isExistUser != 0)
                {
                    response.Success = false;
                    response.Errors.Add("Username Already Exists");
                    return(response);
                }
                //create roles
                var userRoles = new List <UserRolesOld>();
                var id        = Guid.NewGuid();



                foreach (var role in userDto.UserRoles)
                {
                    if (!role.IsSelected)
                    {
                        continue;
                    }
                    dynamic roleNmae = "";
                    switch (role.Role)
                    {
                    case "Investor":
                        roleNmae = RoleName.Investor;
                        break;

                    case "NonInvestor":
                        roleNmae = RoleName.NonInvestor;
                        break;
                    }
                    var userRole = new UserRolesOld()
                    {
                        Id          = Guid.NewGuid(),
                        Role        = roleNmae,
                        CreatedBy   = id,
                        CreatedDate = DateTime.Now,
                        IsActive    = true,
                    };
                    userRoles.Add(userRole);
                }

                PasswordManager passwordManger = new PasswordManager();

                //create new user
                var user = Mapper.Map <UserOld>(userDto);
                user.Id          = id;
                user.Password    = passwordManger.Encrypt(passwordManger.GeneratePassword());
                user.CreatedBy   = user.Id;
                user.CreatedDate = DateTime.Now;
                user.Roles       = userRoles;
                user.IsActive    = true;
                await _usersRepository.AddAsyn(user);

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex.Message);
            }

            return(response);
        }
コード例 #12
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                using (var posContext = new Digital_AppEntities())
                {
                    PasswordManager passwordManager   = new PasswordManager();
                    string          encryptedPassword = passwordManager.Encrypt(txtPassword.Text.Trim());

                    Global.LoggedInUser = posContext.Users.SingleOrDefault(id => id.UserName == txtUserName.Text.Trim() &&
                                                                           id.UserPassword == encryptedPassword &&
                                                                           id.Active == true);


                    if (Global.LoggedInUser != null)
                    {
                        int grpid = (int)Global.LoggedInUser.UserGroupID;
                        Global.LoggedInUserGroup = posContext.UserGroups.SingleOrDefault(id => id.ID == grpid);

                        // int MainBranchID = IdManager.GetShowSingleValueInt("ServerID", "MainBranch", "BranchInfo", "1");
                        // Global.MainBranchID = MainBranchID;

                        int vId = Convert.ToInt32(Global.LoggedInUser.CompanyId);
                        Global.IsLoggedIn  = true;
                        Global.UserLoginID = Global.LoggedInUser.ID;
                        Global.Company     = posContext.CompanyInfoes.SingleOrDefault(c => c.ID == vId);

                        if (Global.LoggedInUserGroup.ID == 4)
                        {
                            AgentMaster.Instance.SetLoggedInUserToStatusStrip(Global.LoggedInUser.ID.ToString(), vId.ToString(), "0", grpid.ToString());

                            AgentMaster.Instance.Show();
                        }
                        else
                        {
                            Master.Instance.SetLoggedInUserToStatusStrip(Global.LoggedInUser, vId.ToString(), "0", grpid.ToString());
                            Master.Instance.Show();
                        }

                        Cursor.Current = Cursors.Default;

                        this.Close();

                        // var item = posContext.View_ItemExpired.FirstOrDefault();
                        // DateTime stardDateTime = DateTime.Parse(item.ExpireDate.ToString());
                        DateTime curreDate = DateTime.Now.AddDays(5);
                        //if (curreDate > stardDateTime)
                        //   {
                        //       DateTime stardDate = Convert.ToDateTime(DateTime.Now.AddDays(5).ToShortDateString());
                        //       var searchData =
                        //           posContext.View_ItemExpired.Where(w => w.ExpireDate == stardDate).ToList();

                        //       if (searchData.Count > 0)
                        //       {
                        //           if (
                        //               MessageBox.Show("Hi User !  You have  " + item.Quantity +"  Items Expired Date. You have  15 days remained.  If you want to show Details Please Click OK Otherwise Click Cancel  ","Warning",
                        //                   MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                        //           {

                        //               frmExpiredDateInfo.Instance.MdiParent = frmPOSMDI.Instance;
                        //               frmExpiredDateInfo.Instance.Show();
                        //           }
                        //       }
                        //   }
                    }
                    else
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Invalid username or password.");
                    }
                }
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;

                if (ex.InnerException != null)
                {
                    if (ex.InnerException.GetType().Name == "SqlException")
                    {
                        int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number;
                        switch (errorNumber)
                        {
                        case 2:
                            MessageBox.Show(ex.InnerException.Message.Substring(0, 148), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        default:
                            MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #13
0
        protected override void Seed(DataBaseContext context)
        {
            IList <Client> defaultStandards = new List <Client>();
            var            clientId         = Guid.NewGuid();

            defaultStandards.Add(new Client()
            {
                client_id = "ReactApp", client_secret = "ReactAppSecret", CreatedDate = DateTime.Now, CreatedBy = clientId, Id = clientId, IsActive = true, Name = "myAPP", RefreshTokenLifeTime = 1400, AllowedOrigin = "http://localhost:3000"
            });

            context.Client.AddRange(defaultStandards);
            var  defaultUser     = new List <UserOld>();
            var  userRoles       = new List <UserRolesOld>();
            Guid userId          = Guid.NewGuid();
            var  supperAdminRole = new UserRolesOld()
            {
                Id          = Guid.NewGuid(),
                Role        = RoleName.SupperAdmin,
                CreatedBy   = userId,
                CreatedDate = DateTime.Now,
                IsActive    = true,
            };
            var adminRole = new UserRolesOld()
            {
                Id          = Guid.NewGuid(),
                Role        = RoleName.Admin,
                CreatedBy   = userId,
                CreatedDate = DateTime.Now,
                IsActive    = true
            };

            userRoles.Add(supperAdminRole);
            userRoles.Add(adminRole);
            var passwordManger = new PasswordManager();

            defaultUser.Add(new UserOld()
            {
                UserName = "******", FirstName = "Test", LastName = "zero", CreatedBy = userId, CreatedDate = DateTime.Now, IsActive = true, Id = userId, LastLoginTime = DateTime.Now, Mobile = "8099686585", Password = passwordManger.Encrypt("Admin123$"), Roles = userRoles
            });

            context.UserOld.AddRange(defaultUser);

            //AddVideoTypeSeed
            //List<VideoType> videoTypes = new List<VideoType>();
            //VideoType videoTypeChapter = new VideoType()
            //{
            //    Id = Guid.NewGuid(),
            //    Name="ChapterVideo",
            //    Description="Contains Chapter Video",
            //    CreatedBy = userId,
            //    CreatedDate = DateTime.Now,
            //    IsActive = true
            //};

            //VideoType videoTypeCourse = new VideoType()
            //{
            //    Id = Guid.NewGuid(),
            //    Name = "CourseVideo",
            //    Description = "Contains Course Video",
            //    CreatedBy = userId,
            //    CreatedDate = DateTime.Now,
            //    IsActive = true
            //};

            //videoTypes.Add(videoTypeChapter);
            //videoTypes.Add(videoTypeCourse);
            //context.VideoType.AddRange(videoTypes);
            context.VideoType.AddRange(AddVideoTypeSeed());
            base.Seed(context);
        }
コード例 #14
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (var posContext = new Digital_AppEntities())
                {
                    User            user;
                    PasswordManager passwordManager = new PasswordManager();
                    if (userID == 0)
                    {
                        user = new User();

                        user.FullName     = txtFullName.Text;
                        user.UserName     = txtUserName.Text;
                        user.UserPassword = passwordManager.Encrypt(txtPassword.Text);
                        user.Mobile       = txtMobile.Text;
                        user.NationalID   = txtNationalID.Text;
                        user.Mobile       = txtMobile.Text;
                        user.Phone        = txtPhone.Text;
                        user.Fax          = txtFax.Text;
                        user.Email        = txtEmail.Text;
                        user.Address1     = txtAddress1.Text;
                        user.Address2     = txtAddress2.Text;
                        user.City         = txtCity.Text;
                        user.State        = txtState.Text;
                        user.PostalCode   = txtPosatalCode.Text;
                        // user.Country = cmbCountry.SelectedItem.ToString();
                        user.UserGroupID = Convert.ToInt16(cmbUserGroup.SelectedValue);
                        user.Active      = chkActive.Checked;
                        user.CreatedBy   = Global.LoggedInUser.ID;
                        user.CreatedDate = DateTime.Now;
                        user.CompanyId   = 1;
                        posContext.Users.Add(user);
                    }
                    else
                    {
                        user              = posContext.Users.Single(id => id.ID == userID);
                        user.FullName     = txtFullName.Text;
                        user.UserName     = txtUserName.Text;
                        user.UserPassword = passwordManager.Encrypt(txtPassword.Text);
                        user.Mobile       = txtMobile.Text;
                        user.NationalID   = txtNationalID.Text;
                        user.Mobile       = txtMobile.Text;
                        user.Phone        = txtPhone.Text;
                        user.Fax          = txtFax.Text;
                        user.Email        = txtEmail.Text;
                        user.Address1     = txtAddress1.Text;
                        user.Address2     = txtAddress2.Text;
                        user.City         = txtCity.Text;
                        user.State        = txtState.Text;
                        user.PostalCode   = txtPosatalCode.Text;
                        // user.Country = cmbCountry.SelectedItem.ToString();
                        user.UserGroupID  = Convert.ToInt16(cmbUserGroup.SelectedValue);
                        user.Active       = chkActive.Checked;
                        user.ModifiedBy   = Global.LoggedInUser.ID;
                        user.ModifiedDate = DateTime.Now;
                        user.CompanyId    = 1;
                    }
                    posContext.SaveChanges();
                    dgvUserInformation.Rows.Clear();

                    foreach (var a in posContext.Users.OrderByDescending(id => id.ID))
                    {
                        dgvUserInformation.Rows.Add(a.ID, a.FullName, a.UserName, a.UserPassword, a.Mobile, a.Phone, a.Fax, a.Email, a.UserGroupID, "", a.NationalID, a.Address1, a.Address2, a.City, a.State, a.PostalCode, a.Active);
                    }
                    isRecordSaved = true;
                    ClearControls();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    if (ex.InnerException.GetType().Name == "SqlException")
                    {
                        int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number;
                        switch (errorNumber)
                        {
                        case 2601:
                            MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        default:
                            MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    if (ex.GetType().Name == "SqlException")
                    {
                        int errorNumber = ((System.Data.SqlClient.SqlException)(ex)).Number;
                        switch (errorNumber)
                        {
                        case 2601:
                            MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        default:
                            MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
コード例 #15
0
 public string GetEncryptedPassword(string password)
 {
     return(_passwordManager.Encrypt(password));
 }
コード例 #16
0
        protected override void Seed(Repositorie.Infrastructure.DataBaseContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            IList <Client> defaultStandards = new List <Client>();
            var            clientId         = Guid.NewGuid();

            defaultStandards.Add(new Client()
            {
                client_id = "ReactApp", client_secret = "ReactAppSecret", CreatedDate = DateTime.Now, CreatedBy = clientId, Id = clientId, IsActive = true, Name = "myAPP", RefreshTokenLifeTime = 1400, AllowedOrigin = "http://localhost:3000"
            });

            context.Client.AddRange(defaultStandards);
            var  defaultUser     = new List <UserOld>();
            var  userRoles       = new List <UserRolesOld>();
            Guid userId          = Guid.NewGuid();
            var  supperAdminRole = new UserRolesOld()
            {
                Id          = Guid.NewGuid(),
                Role        = RoleName.SupperAdmin,
                CreatedBy   = userId,
                CreatedDate = DateTime.Now,
                IsActive    = true,
            };
            var adminRole = new UserRolesOld()
            {
                Id          = Guid.NewGuid(),
                Role        = RoleName.Admin,
                CreatedBy   = userId,
                CreatedDate = DateTime.Now,
                IsActive    = true
            };

            userRoles.Add(supperAdminRole);
            userRoles.Add(adminRole);
            var passwordManger = new PasswordManager();

            defaultUser.Add(new UserOld()
            {
                UserName = "******", FirstName = "Test", LastName = "zero", CreatedBy = userId, CreatedDate = DateTime.Now, IsActive = true, Id = userId, LastLoginTime = DateTime.Now, Mobile = "8099686585", Password = passwordManger.Encrypt("Admin123$"), Roles = userRoles
            });

            context.UserOld.AddRange(defaultUser);
            base.Seed(context);
        }
コード例 #17
0
        private bool CheckPassword(string password, string passwordToCheck)
        {
            ICryptography pass = new PasswordManager();

            return(pass.IsMatch(password, pass.Encrypt(passwordToCheck)));
        }