Add authentication

This commit is contained in:
Robert Marshall 2020-01-03 13:32:20 +00:00
parent 8f0c4c0a45
commit a2d84e182d
11 changed files with 206 additions and 21 deletions

View file

@ -0,0 +1,7 @@
namespace Website.Models {
public class LoginRequest {
public string Username { get; set; }
public string Password { get; set; }
public string ReturnUrl { get; set; }
}
}

29
Website/Models/User.cs Normal file
View file

@ -0,0 +1,29 @@
using System.Security.Cryptography;
using System.Text;
using Website.Data.States;
namespace Website.Models {
public class User {
public User(UserState state) {
Username = state.User_Email;
Password = state.User_Password;
}
public bool ValidatePassword(string password) {
using (var sha256 = SHA256.Create()) {
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
var builder = new StringBuilder();
foreach (var b in hash)
builder.Append(b.ToString("x2"));
var hashString = builder.ToString();
return hashString == Password;
}
}
public string Username { get; set; }
public string Password { get; set; }
}
}