Package pyanaconda :: Package textw :: Module userauth_text
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.textw.userauth_text

  1  # 
  2  # userauth_text.py: text mode authentication setup dialogs 
  3  # 
  4  # Copyright (C) 2000, 2001, 2002, 2008  Red Hat, Inc.  All rights reserved. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 18  # 
 19   
 20  from snack import * 
 21  from constants_text import * 
 22  import pwquality 
 23   
 24  from pyanaconda.constants import * 
 25  import gettext 
 26  _ = lambda x: gettext.ldgettext("anaconda", x) 
 27   
28 -class RootPasswordWindow:
29 - def __call__ (self, screen, anaconda):
30 toplevel = GridFormHelp(screen, _("Root Password"), "rootpw", 1, 3) 31 32 toplevel.add(TextboxReflowed(37, 33 _("Pick a root password. You must " 34 "type it twice to ensure you know " 35 "it and do not make a typing " 36 "mistake. ")), 37 0, 0, (0, 0, 0, 1)) 38 39 if anaconda.users.rootPassword["isCrypted"]: 40 anaconda.users.rootPassword["password"] = "" 41 42 entry1 = Entry(24, password=1, 43 text=anaconda.users.rootPassword["password"]) 44 entry2 = Entry(24, password=1, 45 text=anaconda.users.rootPassword["password"]) 46 passgrid = Grid(2, 2) 47 passgrid.setField(Label(_("Password:")), 0, 0, (0, 0, 1, 0), 48 anchorLeft=1) 49 passgrid.setField(Label(_("Password (confirm):")), 0, 1, (0, 0, 1, 0), 50 anchorLeft=1) 51 passgrid.setField(entry1, 1, 0) 52 passgrid.setField(entry2, 1, 1) 53 toplevel.add(passgrid, 0, 1, (0, 0, 0, 1)) 54 55 bb = ButtonBar(screen, (TEXT_OK_BUTTON, TEXT_BACK_BUTTON)) 56 toplevel.add(bb, 0, 2, growx = 1) 57 58 while 1: 59 toplevel.setCurrent(entry1) 60 result = toplevel.run() 61 rc = bb.buttonPressed(result) 62 if rc == TEXT_BACK_CHECK: 63 screen.popWindow() 64 return INSTALL_BACK 65 if len(entry1.value()) < 6: 66 ButtonChoiceWindow(screen, _("Password Length"), 67 _("The root password must be at least 6 characters long."), 68 buttons = [ TEXT_OK_BUTTON ], width = 50) 69 elif entry1.value() != entry2.value(): 70 ButtonChoiceWindow(screen, _("Password Mismatch"), 71 _("The passwords you entered were different. Please " 72 "try again."), buttons = [ TEXT_OK_BUTTON ], width = 50) 73 elif self.hasBadChars(entry1.value()): 74 ButtonChoiceWindow(screen, _("Error with Password"), 75 _("Requested password contains non-ASCII characters, " 76 "which are not allowed."), 77 buttons = [ TEXT_OK_BUTTON ], width = 50) 78 else: 79 try: 80 settings = pwquality.PWQSettings() 81 settings.read_config() 82 settings.check(entry1.value(), None, "root") 83 except pwquality.PWQError as (e, msg): 84 ret = anaconda.intf.messageWindow(_("Weak Password"), 85 _("You have provided a weak password: %s\n\n" 86 "Would you like to continue with this password?" 87 % (msg, )), 88 type = "yesno", default="no") 89 if ret == 1: 90 break 91 else: 92 break 93 94 entry1.set("") 95 entry2.set("") 96 97 screen.popWindow() 98 anaconda.users.rootPassword["password"] = entry1.value() 99 anaconda.users.rootPassword["isCrypted"] = False 100 return INSTALL_OK
101
102 - def hasBadChars(self, pw):
103 allowed = string.digits + string.ascii_letters + \ 104 string.punctuation + " " 105 for letter in pw: 106 if letter not in allowed: 107 return True 108 return False
109