给你一个程序,有关密码和根据权限访问系统的程序
两个表t_users 和T_rights,其中t_rights用于存放可以访问的菜单项另外,初始超级用户为root.
procedure TFormLogin.MenuDisable;
var
i : Integer;//主菜单计数器
j : Integer;//子菜单计数器
begin
for i := 0 to FormMain.MainMenu.Items.Count - 2do
begin
for j := 0 to FormMain.MainMenu.Items.Count - 1do
begin
FormMain.MainMenu.Items.Items[j].Enabled := False;
end;
end;
FormMain.UserLogin.Enabled := True;
FormMain.MSTClose.Enabled := True;
end;
// 用户能否用菜单
procedure TFormLogin.MenuEnable;
var
i : Integer;//主菜单计数器
j : Integer;//子菜单计数器
sRight : TStringList;
begin
sRight := TStringList.Create ;
if FormMain.LoginUserID = 'root' then
begin
for i := 0 to FormMain.MainMenu.Items.Count -1do
begin
for j := 0 to FormMain.MainMenu.Items.Count -1do
FormMain.MainMenu.Items.Items[j].Enabled := True;
end;
end
else
begin
QueryRights.Close;
QueryRights.SQL.Clear;
QueryRights.SQL.Add('select * from t_Rights where UserID = :UserID');
QueryRights.ParamByName('UserID').AsString := FormMain.LoginUserID;
QueryRights.Open;
while not QueryRights.eofdo
begin
sRight.Add(QueryRights.FieldByName('MenuName').AsString);
QueryRights.Next;
end;
for i := 0 to FormMain.MainMenu.Items.Count -1do
begin
for j := 0 to FormMain.MainMenu.Items.Count - 1do
begin
if sRight.IndexOf(FormMain.MainMenu.Items.Items[j].Name) >= 0 then
begin
FormMain.MainMenu.Items.Items[j].Enabled := True;
end;
end;
end;