コード例 #1
0
ファイル: UserService.cs プロジェクト: shenghai3711/InShare
 /// <summary>
 /// 重置密码
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="pwd"></param>
 /// <returns></returns>
 public bool ResetPassword(long userId, string pwd)
 {
     using (InShareContext db = new InShareContext())
     {
         BaseService <UserEntity> baseService = new BaseService <UserEntity>(db);
         var user = baseService.GetById(userId);
         if (user == null)
         {
             throw new Exception("此用户不存在");
         }
         user.Profile.LastPasswordSalt = user.Profile.PasswordSalt;
         user.Profile.LastPassword     = user.Profile.Password;
         user.Profile.PasswordSalt     = RandomHelper.CreateSalt();
         user.Profile.Password         = EncryptHelper.MD5Encrypt(userId + pwd + user.Profile.PasswordSalt);
         user.Profile.LastEditDateTime = DateTime.Now;
         db.SaveChanges();
         return(true);
     }
 }
コード例 #2
0
ファイル: UserService.cs プロジェクト: shenghai3711/InShare
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="fullName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public long Add(string userName, string fullName, string password)
        {
            long       id   = RandomHelper.CreateId(10);
            string     salt = RandomHelper.CreateSalt();
            UserEntity user = new UserEntity
            {
                Id       = id,
                UserName = userName,
                FullName = fullName,
                Profile  = new UserProfileEntity
                {
                    Id           = id,
                    Password     = EncryptHelper.MD5Encrypt(id + password + salt),
                    PasswordSalt = salt,
                }
            };

            using (InShareContext db = new InShareContext())
            {
                BaseService <UserEntity> baseService = new BaseService <UserEntity>(db);
                while (true)
                {
                    if (baseService.IsExist(user.Id))
                    {
                        user.Id = user.Profile.Id = RandomHelper.CreateId(10);
                    }
                    else
                    {
                        break;
                    }
                }
                db.Users.Add(user);
                db.SaveChanges();
                return(id);
            }
        }