1 public static bool Authenticate(string username, string password)
2 {
3 bool authenticated = false;
4
5
6 NamePasswordCredential credentials;
7 credentials = new NamePasswordCredential(username, password);
8
9 IAuthenticationProvider authprovider;
10 authprovider = AuthenticationFactory.GetAuthenticationProvider();
11
12 IIdentity identity;
13 authenticated = authprovider.Authenticate(credentials, out identity);
14
15 if (!authenticated)
16 {
17 throw new SecurityException("Invalid username or password.");
18 }
19
20
21
22 IRolesProvider rolesprovider;
23 rolesprovider = RolesFactory.GetRolesProvider();
24
25 IPrincipal principal;
26 principal = rolesprovider.GetRoles(identity);
27
28 // Place user's principal on the thread
29 Thread.CurrentPrincipal = principal;
30
31 return authenticated;
32 }这三个概念是:
1. Credential(令牌)
2. Identity(身份)
3. Principal(主体特征)
您理解了吗?


浙公网安备 33010602011771号