blob: 1da6922d9a1e9fd47e6b76a69b238856ae00f7b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
using System.Collections.Generic;
using System.Linq;
using Timeline.Entities;
namespace Timeline.Services
{
public interface IUserService
{
/// <summary>
/// Try to anthenticate with the given username and password.
/// </summary>
/// <param name="username">The username of the user to be anthenticated.</param>
/// <param name="password">The password of the user to be anthenticated.</param>
/// <returns><c>null</c> if anthentication failed.
/// An instance of <see cref="User"/> if anthentication succeeded.</returns>
User Authenticate(string username, string password);
}
public class UserService : IUserService
{
private readonly IList<User> _users = new List<User>{
new User { Id = 0, Username = "admin", Password = "admin", Roles = new string[] { "User", "Admin" } },
new User { Id = 1, Username = "user", Password = "user", Roles = new string[] { "User"} }
};
public User Authenticate(string username, string password)
{
return _users.FirstOrDefault(user => user.Username == username && user.Password == password);
}
}
}
|