Add authentication
This commit is contained in:
parent
8f0c4c0a45
commit
a2d84e182d
11 changed files with 206 additions and 21 deletions
7
Website/Models/LoginRequest.cs
Normal file
7
Website/Models/LoginRequest.cs
Normal 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
29
Website/Models/User.cs
Normal 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; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue