public static Responses.ErrorResponse AttemptCreate(EmailValidationType type,
            String email, out EmailValidationCode valid)
        {
            valid = null;

            if (email == null || email.Length == 0)
                return new Responses.ErrorResponse("no email address given");

            if (!Account.IsEmailValid(email))
                return new Responses.ErrorResponse("invalid email address");

            Account account = DatabaseManager.SelectFirst<Account>(x => x.Email == email);

            if (account == null)
                return new Responses.ErrorResponse("invalid email address");

            valid = EmailValidationCode.Create(type, account);
            valid.SendEmail(account);

            return null;
        }
        public static Responses.ErrorResponse AttemptGet(EmailValidationType type,
            String email, String code, out EmailValidationCode valid, out Account account)
        {
            valid = null;
            account = null;

            if (email == null || email.Length == 0)
                return new Responses.ErrorResponse("no email address given");

            if (!Account.IsEmailValid(email))
                return new Responses.ErrorResponse("invalid email address");

            if (code == null || code.Length == 0)
                return new Responses.ErrorResponse("no validation code given");

            if (!Account.IsPasswordHashValid(code))
                return new Responses.ErrorResponse("invalid validation code");

            account = DatabaseManager.SelectFirst<Account>(x => x.Email == email);

            if (account == null)
                return new Responses.ErrorResponse("invalid email address");

            valid = EmailValidationCode.Get(type, account);

            if (valid == null || !code.EqualsCharArray(valid.Code)) {
                valid = null;
                return new Responses.ErrorResponse("invalid validation code");
            }

            if (valid.IsExpired) {
                valid = null;
                return new Responses.ErrorResponse("expired validation code");
            }

            return null;
        }
        public static EmailValidationCode Create(EmailValidationType type, Account account)
        {
            if (type == EmailValidationType.Activate && account.IsVerified)
                return null;

            EmailValidationCode code = new EmailValidationCode() {
                Type = type,
                AccountID = account.AccountID,
                Code = Tools.GenerateHash(),
                SentDate = DateTime.Now
            };

            if (stCodes[type].ContainsKey(account.AccountID))
                stCodes[type][account.AccountID] = code;
            else
                stCodes[type].Add(account.AccountID, code);

            return code;
        }