Esempio n. 1
0
        public ResponseObject <User> CheckUserCreedientalsDapper(LoginFormData form)
        {
            ResponseObject <User> response = new ResponseObject <User>();

            try
            {
                string username, password;

                username = form.Username;
                password = form.Password;

                User user = CheckCreedientals(form);

                response.Explanation = "Success";
                response.IsSuccess   = true;
                response.StatusCode  = "200";
                response.Object      = user;
            }
            catch (Exception ex)
            {
                response.IsSuccess   = false;
                response.StatusCode  = "400";
                response.Explanation = ex.Message;
            }
            return(response);
        }
Esempio n. 2
0
        public async Task <IActionResult> Login(LoginFormData data)
        {
            if (ModelState.IsValid)
            {
                UserProfile userProfile = await _appDbContext.Users.FirstOrDefaultAsync(u => u.Username == data.Username);

                if (userProfile != null)
                {
                    if (userProfile.PwdHash == data.Password)
                    {
                        await Authenticate(data.Username);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Не правильний пароль");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Не дійсне ім'я користувача");
                }
            }

            return(View(data));
        }
Esempio n. 3
0
        public async Task <IActionResult> Login(LoginFormData formData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await _userManager.FindByNameAsync(formData.UserName);

            if (user != null && await _userManager.CheckPasswordAsync(user, formData.Password))
            {
                var role = await _userManager.GetRolesAsync(user);

                IdentityOptions identityOptions = new IdentityOptions();

                var tokenDescriptor = new SecurityTokenDescriptor {
                    Subject = new ClaimsIdentity(new Claim[] {
                        new Claim("UserID", user.Id),
                        new Claim(identityOptions.ClaimsIdentity.RoleClaimType, role.FirstOrDefault())
                    }),
                    Expires            = DateTime.Now.AddHours(1),
                    SigningCredentials = new SigningCredentials(
                        new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appSettings.JwtKey)), SecurityAlgorithms.HmacSha256Signature)
                };
                var tokenHandler  = new JwtSecurityTokenHandler();
                var securityToken = tokenHandler.CreateToken(tokenDescriptor);
                var token         = tokenHandler.WriteToken(securityToken);

                return(Ok(new { token }));
            }
            else
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }
        }
Esempio n. 4
0
        public User CheckCreedientals(LoginFormData lgnForm)
        {
            string username, password;

            username = lgnForm.Username;
            password = lgnForm.Password;

            User user;

            var userQuery = $"SELECT * FROM usertable WHERE Username='******'";

            user = dapperRepository.Query <User>(userQuery).FirstOrDefault();

            if (user == null)
            {
                throw new Exception("\"Username\" is invalid!");
            }
            else
            {
                if (user.Password.Equals(Cryptography_Algorithms.Calculate_SHA256(password, username + password)))
                {
                    return(user);
                }
                else
                {
                    throw new Exception("Password is invalid!");
                }
            }
        }
        public TransactionObject CheckCreedientals(LoginFormData lgn)
        {
            TransactionObject response = new TransactionObject();
            User user = userManager.GetUserByUsername(lgn.Username);

            if (user == null)
            {
                response.IsSuccess   = false;
                response.Explanation = "Username is invalid!";
            }
            else
            {
                if (SecurityFolder.Security.VerifyPassword(user.Password, lgn.Password))
                {
                    response.IsSuccess   = true;
                    response.Explanation = user.ID.ToString();
                }

                else
                {
                    response.IsSuccess   = false;
                    response.Explanation = "Password is invalid!";
                }
            }
            return(response);
        }
        public ResponseObject <User> CheckCreedientals(LoginFormData lgnForm)
        {
            ResponseObject <User> response = new ResponseObject <User>();
            string username = lgnForm.Username;
            string password = lgnForm.Password;

            User user = userRepository.SingleGetBy(w => w.Username == username);

            if (user == null)
            {
                response.IsSuccess   = false;
                response.StatusCode  = "400";
                response.Explanation = "Username is invalid!";
            }
            else
            {
                if (user.Password.Equals(lgnForm.Password))
                {
                    response.IsSuccess   = true;
                    response.StatusCode  = "200";
                    response.Explanation = "Success";
                }
                else
                {
                    response.IsSuccess   = false;
                    response.StatusCode  = "400";
                    response.Explanation = "Password is invalid!";
                }
            }
            return(response);
        }
Esempio n. 7
0
 public IActionResult Index(LoginFormData data)
 {
     if (ModelState.IsValid)
     {
         return(RedirectToPage("Taskboard"));
     }
     return(View(data));
 }
Esempio n. 8
0
        public JsonResult Login(LoginFormData lgnData)
        {
            var response = accountManager.Login(lgnData);

            Session["Student"] = accountManager.GetStudent(response.ID);
            if (response.TransactionObject.IsSuccess)
            {
                return(Json(new { IsSuccess = true }));
            }
            else
            {
                return(Json(new { IsSuccess = false, Error = response.TransactionObject.Explanation }));
            }
        }
        public LoginResponseObject Login(LoginFormData lgn, bool IsDesktop = false)
        {
            TransactionObject   loginResponse = CheckCreedientals(lgn);
            LoginResponseObject response      = new LoginResponseObject
            {
                TransactionObject = loginResponse
            };

            if (loginResponse.IsSuccess)
            {
                User currentUser = userManager.GetUserByUsername(lgn.Username);
                SetOnlineStatus(userManager.GetUser(currentUser.ID), true, IsDesktop);

                uow.Save();
                response.ID = currentUser.ID;
            }
            return(response);
        }
Esempio n. 10
0
 protected override void OnOpen(object userData)
 {
     base.OnOpen(userData);
     m_LoginFormData = userData as LoginFormData;
     if (userData != null)
     {
     }
     //获取本地存储的账号密码
     if (PlayerPrefs.HasKey("Acct") && PlayerPrefs.HasKey("Pass"))
     {
         iptAcct.text = PlayerPrefs.GetString("Acct");
         iptPass.text = PlayerPrefs.GetString("Pass");
     }
     else
     {
         iptAcct.text = "";
         iptPass.text = "";
     }
 }
Esempio n. 11
0
        public IActionResult GetUserToken([FromBody] LoginFormData lgnForm)
        {
            var response = userManager.CheckUserCreedientalsDapper(lgnForm);
            var user     = response.Object;

            if (user != null)
            {
                try
                {
                    var someClaims = new Claim[] {
                        new Claim("Username", user.Username),
                        new Claim("Password", user.Password),
                        new Claim("SirketKodu", user.SirketKodu),
                        new Claim("NameSurname", user.Name + " " + user.Surname),
                        new Claim("UserID", user.ID.ToString()),
                        new Claim("Rol", user.Yetki)
                    };

                    SecurityKey securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("IDECON1*Pwd is the secret key of this cashflow program"));
                    var         token       = new JwtSecurityToken(
                        issuer: "idecon.com.tr",
                        audience: "ideconclients",
                        claims: someClaims,
                        expires: DateTime.Now.AddHours(12),
                        signingCredentials: new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256)
                        );

                    return(Ok(new JwtSecurityTokenHandler().WriteToken(token)));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(Unauthorized());
            }
        }
        public IHttpActionResult Login(LoginFormData lgnData)
        {
            var response = accountManager.Login(lgnData);

            if (response.TransactionObject.IsSuccess)
            {
                //var serializer = new JsonSerializer();
                //serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                //var jsonResponse = JsonConvert.SerializeObject(response.Student, Formatting.Indented,
                //    new JsonSerializerSettings
                //    {
                //        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                //    });


                //return Ok(JsonConvert.SerializeObject(response, Formatting.Indent, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
                return(Ok(response.ID));
            }
            else
            {
                return(BadRequest(response.TransactionObject.Explanation));
            }
        }