private SignupInfo validateAccountCreationForm(StaplerRequest req, boolean validateCaptcha) {
        // form field validation
        // this pattern needs to be generalized and moved to stapler
        SignupInfo si = new SignupInfo(req);

        if (validateCaptcha && !validateCaptcha(si.captcha)) {
            si.errors.put("captcha", Messages.HudsonPrivateSecurityRealm_CreateAccount_TextNotMatchWordInImage());
        }

        if (si.username == null || si.username.length() == 0) {
            si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameRequired());
        } else if(!containsOnlyAcceptableCharacters(si.username)) {
            if (ID_REGEX == null) {
                si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharacters());
            } else {
                si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharactersCustom(ID_REGEX));
            }
        } else {
            // do not create the user - we just want to check if the user already exists but is not a "login" user.
            User user = User.getById(si.username, false);
            if (null != user)
                // Allow sign up. SCM people has no such property.
                if (user.getProperty(Details.class) != null)
                    si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameAlreadyTaken());
        }

        if (si.password1 != null && !si.password1.equals(si.password2)) {
            si.errors.put("password1", Messages.HudsonPrivateSecurityRealm_CreateAccount_PasswordNotMatch());
        }

        if (!(si.password1 != null && si.password1.length() != 0)) {
            si.errors.put("password1", Messages.HudsonPrivateSecurityRealm_CreateAccount_PasswordRequired());
        }

        if (si.fullname == null || si.fullname.length() == 0) {
            si.fullname = si.username;
        }

        if (isMailerPluginPresent() && (si.email == null || !si.email.contains("@"))) {
            si.errors.put("email", Messages.HudsonPrivateSecurityRealm_CreateAccount_InvalidEmailAddress());
        }

        if (!User.isIdOrFullnameAllowed(si.username)) {
            si.errors.put("username", hudson.model.Messages.User_IllegalUsername(si.username));
        }

        if (!User.isIdOrFullnameAllowed(si.fullname)) {
            si.errors.put("fullname", hudson.model.Messages.User_IllegalFullname(si.fullname));
        }
        req.setAttribute("data", si); // for error messages in the view
        return si;
    }
private SignupInfo validateAccountCreationForm ( StaplerRequest req , boolean validateCaptcha ) { SignupInfo si = new SignupInfo ( req ) ; if ( validateCaptcha && ! validateCaptcha ( si . captcha ) ) { si . errors . put ( "captcha" , Messages . HudsonPrivateSecurityRealm_CreateAccount_TextNotMatchWordInImage ( ) ) ; } if ( si . username == null || si . username . length ( ) == 0 ) { si . errors . put ( "username" , Messages . HudsonPrivateSecurityRealm_CreateAccount_UserNameRequired ( ) ) ; } else if ( ! containsOnlyAcceptableCharacters ( si . username ) ) { if ( ID_REGEX == null ) { si . errors . put ( "username" , Messages . HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharacters ( ) ) ; } else { si . errors . put ( "username" , Messages . HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharactersCustom ( ID_REGEX ) ) ; } } else { User user = User . getById ( si . username , false ) ; if ( null != user ) if ( user . getProperty ( Details . class ) != null ) si . errors . put ( "username" , Messages . HudsonPrivateSecurityRealm_CreateAccount_UserNameAlreadyTaken ( ) ) ; } if ( si . password1 != null && ! si . password1 . equals ( si . password2 ) ) { si . errors . put ( "password1" , Messages . HudsonPrivateSecurityRealm_CreateAccount_PasswordNotMatch ( ) ) ; } if ( ! ( si . password1 != null && si . password1 . length ( ) != 0 ) ) { si . errors . put ( "password1" , Messages . HudsonPrivateSecurityRealm_CreateAccount_PasswordRequired ( ) ) ; } if ( si . fullname == null || si . fullname . length ( ) == 0 ) { si . fullname = si . username ; } if ( isMailerPluginPresent ( ) && ( si . email == null || ! si . email . contains ( "@" ) ) ) { si . errors . put ( "email" , Messages . HudsonPrivateSecurityRealm_CreateAccount_InvalidEmailAddress ( ) ) ; } if ( ! User . isIdOrFullnameAllowed ( si . username ) ) { si . errors . put ( "username" , hudson . model . Messages . User_IllegalUsername ( si . username ) ) ; } if ( ! User . isIdOrFullnameAllowed ( si . fullname ) ) { si . errors . put ( "fullname" , hudson . model . Messages . User_IllegalFullname ( si . fullname ) ) ; } req . setAttribute ( "data" , si ) ; return si ; }
@param req              the request to process
@param validateCaptcha  whether to attempt to validate a captcha in the request

@return a {@link SignupInfo#SignupInfo(StaplerRequest) SignupInfo from given request}, with {@link
SignupInfo#errors} containing errors (keyed by field name), if any of the supported fields are invalid