Exemple #1
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
            {
                Id           = table.Column <int>(nullable: false).Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
                Name         = table.Column <string>(nullable: false, maxLength: 150),
                Username     = table.Column <string>(nullable: false, maxLength: 30),
                Email        = table.Column <string>(nullable: false, maxLength: 75),
                PasswordHash = table.Column <byte[]>(nullable: false),
                PasswordSalt = table.Column <byte[]>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Users", u => u.Id);
            }
                );

            AuthSecurity.CreatePasswordHash("johndoepw", out byte[] pwdHash, out byte[] pwdSalt);

            migrationBuilder.InsertData(
                table: "Users",
                columns: new[] { "Name", "Username", "Email", "PasswordHash", "PasswordSalt" },
                values: new object[] { "John Doe", "johndoe", "*****@*****.**", pwdHash, pwdSalt }
                );
        }
Exemple #2
0
        public IActionResult Authorization(LoginModel loginModel)
        {
            string info = "";

            if (!(loginModel?.IsValid(out info) ?? false))
            {
                return(Error(info));
            }

            loginModel.Login = loginModel.Login.ToLower();

            var user = _userService.GetByLogin(loginModel.Login);

            if (user == null || !AuthSecurity.IsPasswordValid(loginModel.Password, user.Salt, user.Hash))
            {
                return(Error("Неверный логин или пароль"));
            }

            var token = GetIdentity(user.Email, "user");

            _userInfoService.UpdateTimeLastGame(user.Id);

            return(Json(new SorResources.Models.Auth.AuthorizationModel {
                Token = token
            }));
        }
 private void Security_Name_TextChanged(object sender, TextChangedEventArgs e)
 {
     _Name = Security_Name.Text;
     Security_Question.Content = AuthSecurity.RetrieveUserQuestion(_Name);
     if (!Security_Question.Content.Equals(""))
     {
         Security_Answer.Visibility   = Visibility.Visible;
         Security_Question.Visibility = Visibility.Visible;
     }
 }
        protected void FindPassword()
        {
            string response = AuthSecurity.RetrieveUserInfo(_Name, _Secret);

            if (response.Contains("The username "))
            {
                MessageBox.Show(response);
            }
            else if (response.Contains("Incorrect"))
            {
                MessageBox.Show(response);
            }
            else
            {
                MessageBox.Show(response);
            }
        }
Exemple #5
0
        public async Task <User> Authenticate(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);

            if (user == null)
            {
                return(null);
            }

            if (!AuthSecurity.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                return(null);
            }

            return(user);
        }