forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cs
More file actions
74 lines (64 loc) · 1.52 KB
/
User.cs
File metadata and controls
74 lines (64 loc) · 1.52 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Text;
using Waher.Security;
namespace Waher.Networking.XMPP.Chat
{
/// <summary>
/// Chat user
/// </summary>
public class User : IUser
{
private readonly Dictionary<string, bool> privileges = new Dictionary<string, bool>();
private readonly string fullJid;
/// <summary>
/// Chat user
/// </summary>
/// <param name="FullJID">Full JID</param>
public User(string FullJID)
{
this.fullJid = FullJID;
}
/// <summary>
/// User Name.
/// </summary>
public string UserName => this.fullJid;
/// <summary>
/// Password Hash
/// </summary>
public string PasswordHash => string.Empty;
/// <summary>
/// Type of password hash. The empty stream means a clear-text password.
/// </summary>
public string PasswordHashType => string.Empty;
/// <summary>
/// If the user has a given privilege.
/// </summary>
/// <param name="Privilege">Privilege.</param>
/// <returns>If the user has the corresponding privilege.</returns>
public bool HasPrivilege(string Privilege)
{
lock (this.privileges)
{
while (!string.IsNullOrEmpty(Privilege))
{
if (this.privileges.TryGetValue(Privilege, out bool b))
return b;
int i = Privilege.LastIndexOf('.');
if (i < 0)
break;
else
Privilege = Privilege.Substring(0, i);
}
return false;
}
}
internal void SetPrivilege(string Privilege, bool Value)
{
lock (this.privileges)
{
this.privileges[Privilege] = Value;
}
}
}
}