home *** CD-ROM | disk | FTP | other *** search
Wrap
/** * Module: inst_user.ycp * * Authors: Klaus Kaempf (kkaempf@suse.de) * * Purpose: - Ask the user for: * - first name * - last name * - login name * - password * - Check login name and password for validation * - Set user_settings with these values * * user_settings: add: forename * add: surname * add: upassword * add: loginname * * scr: - * * $Id: inst_user.ycp,v 1.64 2000/02/25 12:58:09 sh Exp $ */ { // // A sample (non-root) user is created // string forename = lookup ( user_settings, "forename", "" ); string surname = lookup ( user_settings, "surname", "" ); string password = lookup ( user_settings, "upassword", "" ); string loginname = lookup ( user_settings, "loginname", "" ); boolean test_mode = lookup ( user_settings, "test_mode", false ); boolean this_is_for_real = ! test_mode; // Information about the user. This info is used to create an initial // user account: first name, surname, login name and password. Data // will be written to /etc/passwd. // "Personify" is also the name of the dialog. locale title = _("Personalize"); term contents = `HSquash( `VBox( // User account information, forename or first name `TextEntry(`id("forename"), _("Your first name please:"), forename), // User account information, surname or family name `TextEntry(`id("surname"), _("Your last name please:"), surname), // entry widget for login-name and pushbutton to generate a login name from forename and surname `VSquash(`HBox (`TextEntry(`id("loginname"), _("User login:"), loginname), `Bottom (`PushButton(`id(`propose), _("&Suggestion"))))), // User account information, first version of user password, both versions must match `Password(`id("pw1"), _("Enter a password:"), ""), // User account information, second version of user password, retyped to avoid typos `Password(`id("pw2"), _("Re-enter the password for verification:"), "") ) ); // help text (description of what to do, some background information) // html-format // help part 1 of 5 string helptext = UI(_("<p> Linux is a multiuser system; several different users can log in on the system and work there. In order to avoid confusion of data, each user must identify himself uniquely if he wants to use Linux. </p>")); // help part 2 of 5 helptext = helptext + UI(_("<p> If you fill out the fields (<b>First Name</b> and <b>Last Name</b>), an account is created for an user with this name and a <b>Password</b> is stored. When entering a password, you must distinguish between upper and lower case; a password should have at least 5 characters, and as a rule, not contain any umlauts.")); // help part 3 of 5 helptext = helptext + UI(_(" Possible characters in addition are <tt>#*,.;:._-+!$</tt><tt>%&/|?{[()]}</tt> and blanks and digits <tt>0</tt> to <tt>9</tt>. Often it's enough to use a length of approx. 8 signs for the password. To ensure that the password was entered correctly, you are asked to repeat it exactly in a second field. Make sure you don't forget your password! </p>")); // help part 4 of 5 helptext = helptext + UI(_(" <p> The so-called username is created from components of the full name and presented to you in one of the following dialogs. If unsure, let YaST2 <tt>suggest</tt> an username. You're allowed to modify it, but only use <em>lower</em> case letters (no umlauts!), digits and <tt>._-</tt> - yes, for usernames there's a closer restriction than for passwords! </p>")); // help part 5 of 5 helptext = helptext + UI(_(" <p> If you want to work with Linux, you must first enter the username and the password; this starting procedure is traditionally known as the <b>Login</b>. </p> <br>")); UI(`SetWizardContents(title, contents, helptext, Args(0), Args(1))); UI(`SetFocus(`id(`next))); UI(`SetFocus(`id("forename"))); string valid_logname_chars = "0123456789abcdefghijklmnopqrstuvwxyz"; any ret = nil; while (true) { // FIXME: check login against passwd contents // Please leave this FIXME in, even when fixed, because this might // need adjustments from release to release. list predef_accounts = ReadY2 ("accounts.ycp"); // Clear password fields on every round, unless `propose was // selected. if (ret != `propose) { UI(`ChangeWidget(`id("pw1"), `Value, "")); UI(`ChangeWidget(`id("pw2"), `Value, "")); } ret = UI(`UserInput()); if (ret == `propose) { string default_login_name = "lxuser"; integer part_len = 3; integer login_len = part_len * 2; forename = UI(`QueryWidget(`id("forename"), `Value)); string f_name = filterchars(tolower(forename), valid_logname_chars); integer f_len = size( f_name ); surname = UI(`QueryWidget(`id("surname"), `Value)); string s_name = filterchars(tolower(surname), valid_logname_chars); integer s_len = size( s_name ); if ( f_len == 0 && s_len == 0 ) // both are missing { loginname = default_login_name; // default login } else // at least one is given { if ( f_len >= part_len ) { if ( s_len >= part_len ) // forename and surname long enough { f_len = part_len; // take part_len chars from each s_len = part_len; } else // surname shorter than 3 chars { f_len = login_len - s_len; // fill up with forename } } else // forename shorter than 3 chars { s_len = login_len - f_len; // fill up with surname } // build login name loginname = substring( f_name, 0, f_len ) + substring( s_name, 0, s_len ); if (size (loginname) < 2) loginname = default_login_name; else { string firstchar = substring(loginname, 0, 1); if (firstchar < "a" || firstchar > "z") loginname = default_login_name; } } // check login against passwd contents (default login in case of conflict) if ( contains( predef_accounts, loginname )) loginname = default_login_name; UI(`ChangeWidget( `id("loginname"), `Value, loginname )); } else if (ret == `cancel) break; else { forename = UI(`QueryWidget(`id("forename"), `Value)); surname = UI(`QueryWidget(`id("surname"), `Value)); loginname = UI(`QueryWidget(`id("loginname"), `Value)); string pw1 = UI(`QueryWidget(`id("pw1"), `Value)); string pw2 = UI(`QueryWidget(`id("pw2"), `Value)); user_settings = add (user_settings, "forename", forename); user_settings = add (user_settings, "surname", surname); user_settings = add (user_settings, "loginname", loginname); if (ret == `back) break; if ( this_is_for_real && (forename == "") && (surname == "") ) { // There is a check whether the information from the UI is // correct and complete. The name information is not // complete, the user is asked to complete the information UI(`DisplayMessage(_("Please enter your name."))); UI(`SetFocus(`id("forename"))); continue; } if ( this_is_for_real && loginname == "" ) { // There is a check whether the information from the UI is // correct and complete. The loginname is empty (no user // input). UI(`DisplayMessage(_("You didn't enter a loginname.\nPlease try again."))); UI(`SetFocus(`id("loginname"))); continue; } if ( this_is_for_real && ( size( loginname ) < 2 || size( loginname ) > 8 ) ) { // There is a check whether the information from the UI is // correct and complete. The loginname must have a size // between 2 and 8 characters. UI(`DisplayMessage(_("The login name must have a size between 2 and 8 characters.\nPlease try again."))); UI(`SetFocus(`id("loginname"))); continue; } string firstchar = substring(loginname, 0, 1); if ( this_is_for_real && ( ! (firstchar >= "a" && firstchar <= "z") || nil != findfirstnotof( loginname, valid_logname_chars ) ) ) { // There is a check whether the information from the UI is // correct and complete. The login name may contain only // certain characters and must begin with a letter. UI(`DisplayMessage(_("The login name may contain only\nlower case letters and digits\nand must begin with a letter.\nPlease try again."))); UI(`SetFocus(`id("loginname"))); continue; } // check login against passwd contents if ( contains( predef_accounts, loginname )) { // Tell the user that the login he entered conflicts with // predefined logins in the passwd file. UI(`DisplayMessage(_("\ There is a conflict between the entered\n\ login name and a predefined login name.\n\n\ Please try another one."))); continue; } if ( this_is_for_real && pw1 != pw2 ) { // There is a check whether the information from the UI is // correct and complete. The two user password information // do not match UI(`DisplayMessage(_("The first and the second version\nof the password are different.\nPlease try again."))); password = ""; // Invalidate any old password user_settings = add(user_settings, "upassword", password); UI(`SetFocus(`id("pw1"))); continue; } // Use the old password (if any) if no passwords were entered. // only check pw1 here, its identical with pw2 as checked before if ( this_is_for_real && ( (pw1 != "") || (password == "") ) ) { if ( pw1 == "" ) { // There is a check whether the information from the // UI is correct and complete. The first user password // information is empty (no user input) UI(`DisplayMessage(_("You didn't enter a password.\nPlease try again."))); password = ""; // Invalidate any old password user_settings = add(user_settings, "upassword", password); UI(`SetFocus(`id("pw1"))); continue; } if ( size (pw1) < 5 ) { // There is a check whether the information from the // UI is correct and complete. The user password // information must have a minimal size - 5 characters. UI(`DisplayMessage(_("The password must have at least 5 characters.\nPlease try again."))); password = ""; // Invalidate any old password user_settings = add(user_settings, "upassword", password); UI(`SetFocus(`id("pw1"))); continue; } if ( size(pw1) >= 5 ) { if ( nil != findfirstnotof( pw1, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#* ,.;:._-+!$%&/|\?{[()]}" ) ) { // There is a check whether the information from the // UI is correct and complete. The user password may // contain only certain characters UI(`DisplayMessage(_("The password may only contain the following characters:\n 0..9, a..z, A..Z, and any of \"#* ,.;:._-+!$%&/|\?{[()]}\".\nPlease try again."))); password = ""; // Invalidate any old password user_settings = add(user_settings, "upassword", password); UI(`SetFocus(`id("pw1"))); continue; } } password = crypt (pw1); } user_settings = add(user_settings, "upassword", password); break; } } return ret; }