+ /* print message */
+ display_text(USERNAME_BLURB, user.u_login);
+
+ again:
+ /* get name from user */
+ glogin();
+
+ display_text_line(0);
+ display_text_line("Testing that username...");
+ error = "";
+ if (strlen(user.u_login) < 3)
+ error = "Your username must be at least 3 characters long.";
+ else if (strlen(user.u_login) > 8)
+ error = "Your username cannot be longer than 8 characters.";
+ else if (!isalpha(user.u_login[0]) || !islower(user.u_login[0]))
+ error = "Your username must start with a lowercase letter.";
+ else for (i = 1; i < strlen(user.u_login); i++)
+ if (!islower(user.u_login[i]) &&
+ !isdigit(user.u_login[i]) &&
+ user.u_login[i] != '_')
+ error = "Your username must contain only lower case letters, numbers, and underscore";
+ timer_off();
+ result = krb_get_pw_in_tkt(user.u_login, "", realm,
+ "krbtgt", realm, 1, "");
+ timer_on();
+ if (*error == 0 && result != KDC_PR_UNKNOWN)
+ error = "That username is already taken.";
+
+ /* if it's bad, get another name from user */
+ if (*error) {
+ strcpy(user.u_login, old_login);
+ redisp();
+ display_text_line(error);
+ display_text_line("Please choose another username.");
+ goto again;
+ }
+
+ /* name is OK, make sure */
+ display_text(USERNAME_BLURB2, user.u_login);
+ if (!askyn("Do you want to register this username? (Yes or No) "))
+ goto again;
+
+ display_text_line(0);
+ display_text_line("Trying to assign that username... This may take a few minutes.");
+
+ /* Do It! */
+ timer_off();
+ if (!enrollment)
+ result = grab_login(user.u_first, user.u_last,
+ typed_mit_id, user.u_mit_id,
+ user.u_login);
+ else
+ result = enroll_login(user.u_first, user.u_last,
+ typed_mit_id, user.u_mit_id,
+ user.u_login);
+ wfeep();
+ timer_on();
+ if (result != 0) {
+ char buf[BUFSIZ];
+
+ if (result == UREG_LOGIN_USED) {
+ /* name was in moira but not kerberos */
+ error = "Sorry, that username really was in use after all.";
+ strcpy(user.u_login, old_login);
+ redisp();
+ display_text_line(error);
+ display_text_line("Please choose another username.");
+ goto again;