-
Notifications
You must be signed in to change notification settings - Fork 8
/
Program.cs
executable file
·63 lines (57 loc) · 1.82 KB
/
Program.cs
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
using System;
using Npam;
namespace ConsoleApplication
{
public class Program
{
//const string PamServiceName = "password-auth"; //For RHEL based Linux
const string PamServiceName = "passwd";
public static void Main(string[] args)
{
Console.Write("Username: ");
string user = Console.ReadLine();
Console.Write("Password: ");
string password = AcceptInputNoEcho();
if (NpamUser.Authenticate(PamServiceName, user, password))
{
Console.WriteLine("AUTHENTICATION - SUCCESS!");
Console.WriteLine("\rUSER GROUPS:");
foreach (var userGroup in NpamUser.GetGroups(user))
{
Console.WriteLine("\t{0}", userGroup);
}
Console.WriteLine("\rUSER INFO:");
Console.WriteLine("\t{0}", NpamUser.GetAccountInfo(user));
}
else
{
Console.WriteLine("AUTHENTICATION - FAILURE!");
}
}
private static string AcceptInputNoEcho()
{
string password = "";
while (true)
{
ConsoleKeyInfo i = Console.ReadKey(true);
if (i.Key == ConsoleKey.Enter)
{
Console.WriteLine();
break;
}
else if (i.Key == ConsoleKey.Backspace)
{
if (password.Length > 0)
{
password = password.Substring(0, password.Length - 1);
}
}
else
{
password += (i.KeyChar);
}
}
return password;
}
}
}