File: test.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (202 lines) | stat: -rw-r--r-- 5,721 bytes parent folder | download | duplicates (10)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Configuration;
using System.Configuration.Provider;
using System.Web.Configuration;
using System.Web.Security;
using System.Security;
using System.Security.Principal;

public class Test {
	static void populate_db ()
	{
	}

	static void create_user (string username, string email, string password, string pwdQuestion, string pwdAnswer)
	{
		MembershipCreateStatus status;
		Membership.CreateUser (username, password, email, pwdQuestion, pwdAnswer, true, out status);
		Console.WriteLine ("create status: {0}", status);
	}

	static void generate_password (int length, int numNonAlphNum)
	{
		Console.WriteLine ("generated password = \"{0}\"", Membership.GeneratePassword (length, numNonAlphNum));
	}

	static void dump_list (MembershipUserCollection users)
	{
		Console.WriteLine ("{0} users", users.Count);
		foreach (MembershipUser u in users) {
			Console.WriteLine ("{0} {1} {2}", u.UserName, u.Email, u.IsLockedOut ? "lockedout" : "notlockedout");
		}
	}

	static void list_all_users ()
	{
		MembershipUserCollection users = Membership.GetAllUsers();
		dump_list (users);
	}

	static void validate_user (string username, string password)
	{
		if (Membership.ValidateUser (username, password))
			Console.WriteLine ("success.");
		else
			Console.WriteLine ("failure.");
	}

	static void unlock_user (string username)
	{
		if (Membership.Provider.UnlockUser (username))
			Console.WriteLine ("success.");
		else
			Console.WriteLine ("failure.");
	}

	static void reset_password (string username, string pwdAnswer)
	{
		string newPassword = Membership.Provider.ResetPassword (username, pwdAnswer);

		if (newPassword == null)
			Console.WriteLine ("failure.");
		else
			Console.WriteLine ("success, new password is \"{0}\"", newPassword);
	}

	static void change_password (string username, string oldPwd, string newPwd)
	{
		if (Membership.Provider.ChangePassword (username, oldPwd, newPwd))
			Console.WriteLine ("success.");
		else
			Console.WriteLine ("failure.");
	}

	static void change_question_answer (string username, string pwd, string question, string answer)
	{
		if (Membership.Provider.ChangePasswordQuestionAndAnswer (username, pwd, question, answer))
			Console.WriteLine ("success.");
		else
			Console.WriteLine ("failure.");
	}

	static void find_user_by_email (string pattern)
	{
		MembershipUserCollection users = Membership.FindUsersByEmail (pattern);
		dump_list (users);
	}

	static void find_user_by_name (string pattern)
	{
		MembershipUserCollection users = Membership.FindUsersByName (pattern);
		dump_list (users);
	}

	static void get_number_of_users_online ()
	{
		Console.WriteLine ("Number of online users: {0}", Membership.GetNumberOfUsersOnline ());
	}

	static void get_password (string username, string answer)
	{
		Console.WriteLine ("password for user {0}: {1}", username, Membership.Provider.GetPassword (username, answer));
	}

	static void dump_user (string username)
	{
		Console.WriteLine ("info for user: {0}", username);

		MembershipUser user = Membership.GetUser (username, false);
		Console.WriteLine ("comment: {0}", user.Comment);
		Console.WriteLine ("creation date: {0}", user.CreationDate);
		Console.WriteLine ("email: {0}", user.Email);
		Console.WriteLine ("isApproved: {0}", user.IsApproved);
		Console.WriteLine ("isOnline: {0}", user.IsOnline);
		Console.WriteLine ("last activity date: {0}", user.LastActivityDate);
		Console.WriteLine ("last login date: {0}", user.LastLoginDate);
		Console.WriteLine ("last password changed date: {0}", user.LastPasswordChangedDate);
		Console.WriteLine ("last lockout date: {0}", user.LastLockoutDate);
	}

	static void Usage ()
	{
		Console.WriteLine ("usage:   just look at test.cs...");
	}

	public static void Main (string[] args) {
		if (args.Length == 0) {
			Usage ();
			return;
		}

		switch (args[0]) {
		case "populate":
			populate_db ();
			break;
		case "createuser":
			create_user (args[1], args[2], args[3], args[4], args[5]);
			break;
		case "listallusers":
			list_all_users ();
			break;
		case "generatepassword":
			generate_password (Int32.Parse (args[1]), Int32.Parse (args[2]));
			break;
		case "validateuser":
			validate_user (args[1], args[2]);
			break;
		case "unlockuser":
			unlock_user (args[1]);
			break;
		case "resetpassword":
			reset_password (args[1], args[2]);
			break;
		case "changepassword":
			change_password (args[1], args[2], args[3]);
			break;
		case "changequestionanswer":
			change_question_answer (args[1], args[2], args[3], args[4]);
			break;
		case "dumpuser":
			dump_user (args[1]);
			break;
		case "findusersbyemail":
			find_user_by_email (args[1]);
			break;
		case "findusersbyname":
			find_user_by_name (args[1]);
			break;
		case "getnumberofusersonline":
			get_number_of_users_online ();
			break;
		case "getpassword":
			get_password (args[1], args[2]);
			break;
		default:
			Console.WriteLine ("unknown command {0}", args[0]);
			break;
		}
	}
}



public class ProvPoker : Toshok.Web.Security.SqlMembershipProvider {
	protected override byte[] EncryptPassword (byte[] pwd) {
		Console.WriteLine ("pwd = ({0})", Convert.ToBase64String (pwd));
		byte[] buf = base.EncryptPassword (pwd);
		Console.WriteLine ("buf = {0} bytes long ({1})", buf.Length, Convert.ToBase64String (buf));
		return buf;
	}

	protected override byte[] DecryptPassword (byte[] pwd) {
		Console.WriteLine ("pwd = ({0})", Convert.ToBase64String (pwd));
		byte[] buf = base.DecryptPassword (pwd);
		Console.WriteLine ("buf = {0} bytes long ({1})", buf.Length, Convert.ToBase64String (buf));
		return buf;
	}
}