/// <summary> /// Sign a client up for the service. Will fail if username is already in user, or email is not formatted validly. /// </summary> /// <param name="username">Client username.</param> /// <param name="password">Client password.</param> /// <param name="email">Client email.</param> /// <returns>The outcome of the operation.</returns> public Response MobileSignUp(string username, string password, string email) { using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection Response r = db.OpenConnection(); if (r.error) return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0); // Escape to allow the MobileTestClient to list all Mobile information // WILL BE REMOVED FOR RELEASE! if (username.Equals("list", StringComparison.OrdinalIgnoreCase)) { Response listResponse = db.MobileListMembers(); if (listResponse.error) return (Response) Common.LogError(listResponse.message, Environment.StackTrace, listResponse, 0); return listResponse; } // Validate that username and password are not blank. if (username.Length == 0 || password.Length == 0) { r.error = true; r.message = "Username or password is blank."; return r; } // Validate that username and password are not too long. if (username.Length > 20 || password.Length > 20) { r.error = true; r.message = "Username or password is longer than 20 characters."; return r; } // Validate the email address. try { var address = new System.Net.Mail.MailAddress(email); } catch { r.error = true; r.message = "Email address is not valid"; return r; } // Try to see if the username already exists. If it does, inform the client. r = db.MobileValidateUsername(username); if (r.error) return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0); if (r.message.Trim() != string.Empty) { r.error = true; r.message = "That username already exists."; return r; } // Create salt and hashed/salted password; string salt = Common.CreateSalt(16); string hashSaltPassword = Common.CreatePasswordHash(password, salt); // Information seems valid, sign up client and return successfulness. r = db.MobileSignUp(username, hashSaltPassword, email, salt); if(r.error) return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0); return r; } }
/// <summary> /// Sign a client up for the service. Will fail if username is already in user, or email is not formatted validly. /// </summary> /// <param name="username">Client username.</param> /// <param name="password">Client password.</param> /// <param name="email">Client email.</param> /// <returns>The outcome of the operation.</returns> public Response MobileSignUp(string username, string password, string email) { using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection ExpResponse r = db.OpenConnection(); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile); // Escape to allow the MobileTestClient to list all Mobile information // WILL BE REMOVED FOR RELEASE! if (username.Equals("list", StringComparison.OrdinalIgnoreCase)) { ExpResponse listResponse = db.MobileListMembers(); if (listResponse.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile); return listResponse; } // Validate that username and password are not blank. if (username.Length == 0 || password.Length == 0) { r.setErMsg(true, Messages.ERR_CRED_BLANK); return r; } // Validate that username and password are not too long. if (username.Length > 20 || password.Length > 20) { r.setErMsg(true, Messages.ERR_CRED_LONG); return r; } // Validate the email address. try { var address = new System.Net.Mail.MailAddress(email); } catch { r.setErMsg(true, Messages.ERR_BAD_EMAIL); return r; } // Try to see if the username already exists. If it does, inform the client. r = db.MobileValidateUsername(username); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile); if (r.message.Trim() != string.Empty) { r.setErMsg(true, Messages.ERR_CRED_TAKEN); return r; } // Create salt and hashed/salted password; string salt = Common.CreateSalt(16); string hashSaltPassword = Common.CreatePasswordHash(password, salt); // Information seems valid, sign up client and return successfulness. r = db.MobileSignUp(username, hashSaltPassword, email, salt); if(r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile); return r; } }