Beispiel #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="db"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async static Task <LoginOrRegisterResult> LoginAsync(PublicBicyclesContext db, string username, string password)
        {
            //判断参数是否为空
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                return(new LoginOrRegisterResult()
                {
                    Type = LoginOrRegisterResultType.Empty
                });
            }
            //寻找用户名与密码都匹配的用户
            User user = await db.Users
                        .FirstOrDefaultAsync(p => p.Username == username && p.Password == CreateMD5(username + password));

            if (user == null)
            {
                //返回用户名或密码错误
                return(new LoginOrRegisterResult()
                {
                    Type = LoginOrRegisterResultType.Wrong
                });
            }
            db.Entry(user).State = EntityState.Modified;
            //修改并保存用户信息
            await db.SaveChangesAsync();

            return(new LoginOrRegisterResult()
            {
                User = user
            });
        }
Beispiel #2
0
 /// <summary>
 /// 设置密码
 /// </summary>
 /// <param name="db"></param>
 /// <param name="user">车主</param>
 /// <param name="password">新密码</param>
 /// <returns></returns>
 public async static Task SetPasswordAsync(PublicBicyclesContext db, User user, string password)
 {
     user.Password        = CreateMD5(user.Username + password);
     db.Entry(user).State = EntityState.Modified;
     await db.SaveChangesAsync();
 }