Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.03 KB | None | 0 0
  1. [Serializable]
  2. class playersignup
  3. {
  4.  
  5. //variables set to private
  6. private string firstname;
  7. private string secondname;
  8. private DateTime dateofbirth = new DateTime();
  9. private string email;
  10. private string username;
  11. private string password;
  12. private string reenterpassword;
  13. private string combobox;
  14. private int score;
  15. public string errormessage;
  16.  
  17. public playersignup()//default constructor-special member function of a class that is executed whenever we create new objects of that class.
  18. {
  19.  
  20. }
  21. public playersignup(string fn, string sn, DateTime dob, string em, string un, string pw, string repw, string cb)//parametired constructor, helps you assign initial value to an object at the time of its creation, both constrcutors are needed when creating a class
  22. {
  23. firstname = fn;
  24. secondname = sn;
  25. dateofbirth = dob;
  26. email = em;
  27. username = un;
  28. password = pw;
  29. reenterpassword = repw;
  30. combobox = cb;
  31. // score = s;
  32. }
  33. //properties are special type of class members that provides a flexible mechansim to read,write or compute the value of the private fields as shown get and set which helps to access and modify the propeerties. the both get and set properties are set so it has both read and write properties
  34. public string Firstname
  35. {
  36. get { return firstname; }
  37. set
  38. {
  39. bool valid = validfirstname(value);
  40. if (valid == true)
  41. firstname = value;
  42. else
  43. throw new ExceptionClass(errormessage);//this in all the properties as this calls the exception class which is carried out if there is invalid input from the methods below and is checked in the set part and is thrown and then catched if invalid in try and catch blocks in sign up form
  44.  
  45. }
  46. }
  47. public string Secondname
  48. {
  49. get { return secondname; }
  50. set
  51. {
  52. bool valid = validsecondname(value);
  53. if (valid == true)
  54. secondname = value;
  55. else
  56. throw new ExceptionClass(errormessage);
  57.  
  58.  
  59. }
  60. }
  61. public DateTime Dateofbirth
  62. {
  63. get { return dateofbirth; }
  64. set
  65. {
  66. bool valid = validDOB(value);
  67. if (valid == true)
  68. dateofbirth = value;
  69. else throw new ExceptionClass(errormessage);
  70. }
  71. }
  72. public string Email
  73. {
  74. get { return email; }
  75. set
  76. {
  77. bool valid = validemail(value);
  78. if (valid == true)
  79. email = value;
  80. else throw new ExceptionClass(errormessage);
  81. }
  82. }
  83. public string Username
  84. {
  85. get { return username; }
  86. set
  87. {
  88.  
  89. bool valid = validusername(value);
  90. if (valid == true)
  91. username = value;
  92. else throw new ExceptionClass(errormessage);
  93. }
  94. }
  95. public string Password
  96. {
  97. get { return password; }
  98. set
  99. {
  100.  
  101. bool valid = validpassword(value);
  102. if (valid == true)
  103. password = value;
  104. else throw new ExceptionClass(errormessage);
  105. }
  106. }
  107. public string Reenterpassword
  108. {
  109. get { return reenterpassword; }
  110. set
  111. {
  112. bool valid = validreenteredpassword(value);
  113. if (valid == true)
  114. reenterpassword = value;
  115. else throw new ExceptionClass(errormessage);
  116. }
  117. }
  118. public string ComboBox
  119. {
  120. get { return combobox; }
  121. set
  122. {
  123. bool valid = Validcombobox(value);
  124. if (valid == true)
  125. combobox = value;
  126. else throw new ExceptionClass(errormessage);
  127. }
  128. }
  129. public int Score
  130. {
  131. get { return score; }
  132. set { score = value; }
  133. }
  134. public bool validemail(string em)
  135. {
  136. if ((em.EndsWith(".com") || em.EndsWith(".net") && (em.Contains("@"))))
  137. {
  138. return true;
  139. }
  140. else if (em.Length == 0)
  141. {
  142. errormessage = "No email address entered.It must contain '@' and end with '.com' or '.net'";
  143. return false;
  144. }
  145. else
  146. {
  147. errormessage = "Invalid email address entered.It must contain '@' and end with '.com' or '.net'";
  148. return false;
  149. }
  150. }
  151. public string toString(string[,] playerdetails)
  152. {
  153. return string.Format(" Username:{0} Password:{1} Score:{2}", username, password,score);
  154. }
  155. // validation methods, for all the data which is needed to sign up, making the user input have to inpur specific data as set below, they wont be allow to sign up if the data does match the requirements set as below for all the data
  156. public bool validpassword(string pw)
  157. {
  158. int numbercounter = 0;
  159. int uppercasecounter = 0;
  160. int lowercasecounter = 0;
  161. int alphanumericcounter = 0;
  162. for (int x = 0; x < pw.Length; x++)
  163. {
  164. if (char.IsDigit(pw[x]))
  165. numbercounter++;
  166. else if (char.IsUpper(pw[x]))
  167. uppercasecounter++;
  168. else if (char.IsLower(pw[x]))
  169. lowercasecounter++;
  170. if (char.IsLetterOrDigit(pw[x]))
  171. alphanumericcounter++;
  172. }
  173. if ((numbercounter >= 1) && (alphanumericcounter == pw.Length) && (pw.Length >= 7 && pw.Length <= 15) && (lowercasecounter >= 1) && (uppercasecounter >= 1))
  174. return true;
  175. else if (pw.Length == 0)
  176. {
  177. errormessage = "No password entered, it must contain numbers and letters, contain at least one number, must be at least 7 characters long and no more than 15and must contain at least one upper and lower case letter ";
  178. return false;
  179. }
  180.  
  181. else
  182. {
  183. errormessage = "Invalid password entered, it must be only numbers and letters,contain at least one number,must be at least 7 characters long and no more than 15and must contain at least one upper and lower case letter ";
  184. return false;
  185. }
  186. }
  187. public bool validusername(string um)
  188. {
  189. int numbercounter = 0;
  190. int uppercasecounter = 0;
  191. int lowercasecounter = 0;
  192. for (int x = 0; x < um.Length; x++)
  193. {
  194. if (char.IsLower(um[x]))
  195. lowercasecounter++;
  196. else if (char.IsUpper(um[x]))
  197. uppercasecounter++;
  198. else if (char.IsDigit(um[x]))
  199. numbercounter++;
  200. }
  201. if ((um.Length >= 5 && um.Length <= 14) && (numbercounter >= 1) && (lowercasecounter >= 1) && (uppercasecounter >= 1))
  202. return true;
  203. else if (um.Length == 0)
  204. {
  205. errormessage = "No username entered. it must be at least 5 characters in length and no more than 14,must have at least need 1 number and at least 1 uppercase and lowercase letter";
  206. return false;
  207. }
  208. else
  209. {
  210. errormessage = "invalid username entered. it must be at least 5 characters in length and no more than 14,must have at least need 1 number and at least 1 uppercase and lowercase letter";
  211. return false;
  212. }
  213. }
  214. public bool validfirstname(string fn)
  215. {
  216. int lettercounter = 0;
  217. int spacecounter = 0;
  218. for (int x = 0; x < fn.Length; x++)
  219. {
  220. if (char.IsLetter(fn[x]))
  221. lettercounter++;
  222. if (char.IsWhiteSpace(fn[x]) || char.IsPunctuation(fn[x]))
  223. spacecounter++;
  224. }
  225. if (fn.Length == 0)
  226. {
  227. errormessage = "No first name entered, must only include letters(blank spaces allowed)";
  228. return false;
  229. }
  230. else if (fn.Length != lettercounter + spacecounter && lettercounter > 0)
  231. {
  232. fn = null;
  233. errormessage = "invalid input,first name must contain letters (blank spaces allowed)";
  234. return false;
  235. }
  236. else
  237. return true;
  238.  
  239. }
  240. public bool validsecondname(string sn)
  241. {
  242.  
  243. int lettercounter = 0;
  244. int spacecounter = 0;
  245. for (int x = 0; x < sn.Length; x++)
  246. {
  247. if (char.IsLetter(sn[x]))
  248. lettercounter++;
  249. if (char.IsWhiteSpace(sn[x]) || char.IsPunctuation(sn[x]))
  250. spacecounter++;
  251. }
  252. if (sn.Length == 0)
  253. {
  254. errormessage = "No Second name entered,must only include letters(blank spaces allowed)";
  255. return false;
  256. }
  257. else if (sn.Length != lettercounter + spacecounter && lettercounter > 0)
  258. {
  259. errormessage = "second name must only contain letters(blank spaces allowed";
  260. return false;
  261. }
  262. else
  263. return true;
  264. }
  265. public bool validreenteredpassword(string repw)
  266. {
  267.  
  268. if (repw == password)
  269. return true;
  270. else if (repw.Length == 0)
  271. {
  272. errormessage = "No input, you must re-enter your password";
  273. return false;
  274. }
  275. else
  276. {
  277. errormessage = "The passwords do not match";
  278. return false;
  279. }
  280. }
  281. public bool validDOB(DateTime dob)
  282. {
  283. if (dob.Year > 2007)
  284. {
  285. errormessage = "you must be 12 or over to play this game";
  286. return false;
  287. }
  288. else
  289. {
  290. return true;
  291. }
  292.  
  293.  
  294. }
  295. public bool Validcombobox(string malefemale)
  296. {
  297. if (malefemale.Length == 0)
  298. {
  299. errormessage = "no gender selected";
  300. return false;
  301. }
  302. else return true;
  303. }
  304. }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement