コード例 #1
0
ファイル: AuthUserX.cs プロジェクト: aliaa/TciPM.Blazor
        public static AuthUserX CheckAuthentication(IDbContext db, string username, string password, bool passwordIsHashed = false)
        {
            string hash;

            if (passwordIsHashed)
            {
                hash = password;
            }
            else
            {
                hash = AuthUserDBExtention.GetHash(password);
            }
            string    ip   = null; //TODO
            AuthUserX user = db.Find <AuthUserX>(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true).FirstOrDefault();

            if (user != null && (string.IsNullOrEmpty(user.RestrictedIP) || ip == user.RestrictedIP))
            {
                db.Save(new LoginLog {
                    Sucess = true, UserId = user.Id, Username = user.Username, IP = ip
                });
                return(user);
            }

            db.Save(new LoginLog {
                Sucess = false, Username = username, IP = ip
            });
            return(null);
        }
コード例 #2
0
        public static AuthUserX CheckAuthentication(this IDbContext db, string username, string password, bool passwordIsHashed = false)
        {
            string hash;

            if (passwordIsHashed)
            {
                hash = password;
            }
            else
            {
                hash = AuthUserDBExtention.GetHash(password);
            }
            string ip   = null; //TODO
            var    user = db.FindFirst <AuthUserX>(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true);

            if (user != null)
            {
                db.Save(new LoginLog {
                    Sucess = true, UserId = user.Id, Username = user.Username, IP = ip
                });
                return(user);
            }

            db.Save(new LoginLog {
                Sucess = false, Username = username, IP = ip
            });
            return(null);
        }
コード例 #3
0
        public async Task <IActionResult> ChangePassword(ChangePasswordVM model)
        {
            var user = userCol.FindFirst(u => u.Id == UserId);

            if (user != null)
            {
                if (AuthUserDBExtention.GetHash(model.CurrentPassword) == user.HashedPassword)
                {
                    if (model.NewPassword == model.RepeatNewPassword)
                    {
                        user.Password = model.NewPassword;
                        await userCol.InsertOneAsync(user);

                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest("رمز جدید و تکرار آن باهم برابر نیستند."));
                    }
                }
                else
                {
                    return(BadRequest("رمز فعلی اشتباه میباشد."));
                }
            }
            return(Unauthorized());
        }
コード例 #4
0
        public IActionResult ChangePassword(ChangePasswordVM model)
        {
            var user = db.FindFirst <AuthUserX>(u => u.Id == UserId);

            if (user != null)
            {
                if (AuthUserDBExtention.GetHash(model.CurrentPassword) == user.HashedPassword)
                {
                    if (model.NewPassword == model.RepeatNewPassword)
                    {
                        user.Password = model.NewPassword;
                        db.Save(user);
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest("رمز جدید و تکرار آن باهم برابر نیستند."));
                    }
                }
                else
                {
                    return(BadRequest("رمز فعلی اشتباه می‌باشد."));
                }
            }
            return(Unauthorized());
        }
コード例 #5
0
        public static AuthUserX CheckAuthentication(this IMongoCollection <AuthUserX> userCol, string username, string password, bool passwordIsHashed = false)
        {
            string hash;

            if (passwordIsHashed)
            {
                hash = password;
            }
            else
            {
                hash = AuthUserDBExtention.GetHash(password);
            }
            return(userCol.FindFirst(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true));
        }
コード例 #6
0
        public static AuthUserX CheckAuthentication(this IDbContext DB, string username, string password, bool passwordIsHashed = false)
        {
            string hash;

            if (passwordIsHashed)
            {
                hash = password;
            }
            else
            {
                hash = AuthUserDBExtention.GetHash(password);
            }
            return(DB.FindFirst <AuthUserX>(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true));
        }