1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
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