9d2e3597b76be054decfd804f6569afc8010df78
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / lua / configure / menu / 100_set_root_password.lua
1 -- $Id: 100_set_root_password.lua,v 1.6 2005/03/29 18:00:18 den Exp $
2
3 require "gettext"
4
5 local set_root_password = function()
6         local done = false
7         local result
8         local cmds
9         local form = {
10             id = "root_passwd",
11             name = _("Set Root Password"),
12             short_desc = _(
13                 "Here you can set the super-user (root) password."
14             ),
15
16             fields = {
17                 {
18                     id = "root_passwd_1",
19                     name = _("Root Password"),
20                     short_desc = _("Enter the root password you would like to use"),
21                     obscured = "true"
22                 },
23                 {
24                     id = "root_passwd_2",
25                     name = _("Re-type Root Password"),
26                     short_desc = _("Enter the same password again to confirm"),
27                     obscured = "true"
28                 }
29             },
30             
31             actions = {
32                 {
33                     id = "ok",
34                     name = _("Accept and Set Password")
35                 },
36                 {
37                     id = "cancel",
38                     name = _("Return to Configure Menu")
39                 }
40             },
41
42             datasets = {
43                 { root_passwd_1 = "", root_passwd_2 = "" }
44             }
45         }
46
47         while not done do
48                 result = App.ui:present(form)
49
50                 if result.action_id == "ok" then
51                         form.datasets = result.datasets
52
53                         --
54                         -- Fetch form field values.
55                         --
56
57                         local root_passwd_1 = result.datasets[1].root_passwd_1
58                         local root_passwd_2 = result.datasets[1].root_passwd_2
59                         
60                         --[[
61                         if (!assert_clean(a->c, _("Root Password"), root_passwd_1, PW_NOT_ALLOWED)) {
62                                 done = 0;
63                         ]]--
64                         
65                         if root_passwd_1 == root_passwd_2 then
66                                 --
67                                 -- Passwords match, so set the root password.
68                                 --
69                                 cmds = CmdChain.new()
70                                 App.state.target:cmds_set_password(cmds,
71                                     "root", root_passwd_1)
72                                 if cmds:execute() then
73                                         App.ui:inform(
74                                             _("The root password has been changed.")
75                                         )
76                                         done = true
77                                 else
78                                         App.ui:inform(
79                                             _("An error occurred when " ..
80                                               "setting the root password.")
81                                         )
82                                         done = false
83                                 end
84                         else
85                                 --
86                                 -- Passwords don't match - tell the user, let them try again.
87                                 --
88                                 App.ui:inform(
89                                     _("The passwords do not match.")
90                                 )
91                                 done = false
92                         end
93                 else
94                         -- Cancelled
95                         done = true
96                 end
97         end
98 end
99
100 return {
101     name = _("Set Root Password"),
102     effect = function()
103         set_root_password()
104         return Menu.CONTINUE
105     end
106 }