Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable]
- class playersignup
- {
- //variables set to private
- private string firstname;
- private string secondname;
- private DateTime dateofbirth = new DateTime();
- private string email;
- private string username;
- private string password;
- private string reenterpassword;
- private string combobox;
- private int score;
- public string errormessage;
- public playersignup()//default constructor-special member function of a class that is executed whenever we create new objects of that class.
- {
- }
- 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
- {
- firstname = fn;
- secondname = sn;
- dateofbirth = dob;
- email = em;
- username = un;
- password = pw;
- reenterpassword = repw;
- combobox = cb;
- // score = s;
- }
- //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
- public string Firstname
- {
- get { return firstname; }
- set
- {
- bool valid = validfirstname(value);
- if (valid == true)
- firstname = value;
- else
- 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
- }
- }
- public string Secondname
- {
- get { return secondname; }
- set
- {
- bool valid = validsecondname(value);
- if (valid == true)
- secondname = value;
- else
- throw new ExceptionClass(errormessage);
- }
- }
- public DateTime Dateofbirth
- {
- get { return dateofbirth; }
- set
- {
- bool valid = validDOB(value);
- if (valid == true)
- dateofbirth = value;
- else throw new ExceptionClass(errormessage);
- }
- }
- public string Email
- {
- get { return email; }
- set
- {
- bool valid = validemail(value);
- if (valid == true)
- email = value;
- else throw new ExceptionClass(errormessage);
- }
- }
- public string Username
- {
- get { return username; }
- set
- {
- bool valid = validusername(value);
- if (valid == true)
- username = value;
- else throw new ExceptionClass(errormessage);
- }
- }
- public string Password
- {
- get { return password; }
- set
- {
- bool valid = validpassword(value);
- if (valid == true)
- password = value;
- else throw new ExceptionClass(errormessage);
- }
- }
- public string Reenterpassword
- {
- get { return reenterpassword; }
- set
- {
- bool valid = validreenteredpassword(value);
- if (valid == true)
- reenterpassword = value;
- else throw new ExceptionClass(errormessage);
- }
- }
- public string ComboBox
- {
- get { return combobox; }
- set
- {
- bool valid = Validcombobox(value);
- if (valid == true)
- combobox = value;
- else throw new ExceptionClass(errormessage);
- }
- }
- public int Score
- {
- get { return score; }
- set { score = value; }
- }
- public bool validemail(string em)
- {
- if ((em.EndsWith(".com") || em.EndsWith(".net") && (em.Contains("@"))))
- {
- return true;
- }
- else if (em.Length == 0)
- {
- errormessage = "No email address entered.It must contain '@' and end with '.com' or '.net'";
- return false;
- }
- else
- {
- errormessage = "Invalid email address entered.It must contain '@' and end with '.com' or '.net'";
- return false;
- }
- }
- public string toString(string[,] playerdetails)
- {
- return string.Format(" Username:{0} Password:{1} Score:{2}", username, password,score);
- }
- // 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
- public bool validpassword(string pw)
- {
- int numbercounter = 0;
- int uppercasecounter = 0;
- int lowercasecounter = 0;
- int alphanumericcounter = 0;
- for (int x = 0; x < pw.Length; x++)
- {
- if (char.IsDigit(pw[x]))
- numbercounter++;
- else if (char.IsUpper(pw[x]))
- uppercasecounter++;
- else if (char.IsLower(pw[x]))
- lowercasecounter++;
- if (char.IsLetterOrDigit(pw[x]))
- alphanumericcounter++;
- }
- if ((numbercounter >= 1) && (alphanumericcounter == pw.Length) && (pw.Length >= 7 && pw.Length <= 15) && (lowercasecounter >= 1) && (uppercasecounter >= 1))
- return true;
- else if (pw.Length == 0)
- {
- 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 ";
- return false;
- }
- else
- {
- 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 ";
- return false;
- }
- }
- public bool validusername(string um)
- {
- int numbercounter = 0;
- int uppercasecounter = 0;
- int lowercasecounter = 0;
- for (int x = 0; x < um.Length; x++)
- {
- if (char.IsLower(um[x]))
- lowercasecounter++;
- else if (char.IsUpper(um[x]))
- uppercasecounter++;
- else if (char.IsDigit(um[x]))
- numbercounter++;
- }
- if ((um.Length >= 5 && um.Length <= 14) && (numbercounter >= 1) && (lowercasecounter >= 1) && (uppercasecounter >= 1))
- return true;
- else if (um.Length == 0)
- {
- 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";
- return false;
- }
- else
- {
- 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";
- return false;
- }
- }
- public bool validfirstname(string fn)
- {
- int lettercounter = 0;
- int spacecounter = 0;
- for (int x = 0; x < fn.Length; x++)
- {
- if (char.IsLetter(fn[x]))
- lettercounter++;
- if (char.IsWhiteSpace(fn[x]) || char.IsPunctuation(fn[x]))
- spacecounter++;
- }
- if (fn.Length == 0)
- {
- errormessage = "No first name entered, must only include letters(blank spaces allowed)";
- return false;
- }
- else if (fn.Length != lettercounter + spacecounter && lettercounter > 0)
- {
- fn = null;
- errormessage = "invalid input,first name must contain letters (blank spaces allowed)";
- return false;
- }
- else
- return true;
- }
- public bool validsecondname(string sn)
- {
- int lettercounter = 0;
- int spacecounter = 0;
- for (int x = 0; x < sn.Length; x++)
- {
- if (char.IsLetter(sn[x]))
- lettercounter++;
- if (char.IsWhiteSpace(sn[x]) || char.IsPunctuation(sn[x]))
- spacecounter++;
- }
- if (sn.Length == 0)
- {
- errormessage = "No Second name entered,must only include letters(blank spaces allowed)";
- return false;
- }
- else if (sn.Length != lettercounter + spacecounter && lettercounter > 0)
- {
- errormessage = "second name must only contain letters(blank spaces allowed";
- return false;
- }
- else
- return true;
- }
- public bool validreenteredpassword(string repw)
- {
- if (repw == password)
- return true;
- else if (repw.Length == 0)
- {
- errormessage = "No input, you must re-enter your password";
- return false;
- }
- else
- {
- errormessage = "The passwords do not match";
- return false;
- }
- }
- public bool validDOB(DateTime dob)
- {
- if (dob.Year > 2007)
- {
- errormessage = "you must be 12 or over to play this game";
- return false;
- }
- else
- {
- return true;
- }
- }
- public bool Validcombobox(string malefemale)
- {
- if (malefemale.Length == 0)
- {
- errormessage = "no gender selected";
- return false;
- }
- else return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement