lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Monday 30 May 2005 08:23, Stukov wrote:
[...]
> But I want to hide 'GetAdminPassword' from ENUMERATING.

You can't.

Lua doesn't have the concept of methods. What you've got is a table containing 
references to functions; each 'method' is just another table entry. 
Enumeration is one of the core operations you can perform on a table.

The closest thing you could do is to use upvalues so that your 
GetAdminPassword routine isn't stored in the table:

function generateMetatable()
 function GetAdminPassword(self)
 end

 function CurrentAccount(self)
 end

 function CurrentPassword(self)
  ...
  getAdminPassword(self)
  ...
 end

 return {CurrentAccount, CurrentPassword}
end

But this means that the routine can't be called by the user at all.

> Of course, if user knows that 'bank' table has method 'GetAdminPassword',
> he can call it.

I would strongly suggest that you may need to rephrase your problem --- this 
doesn't give you any kind of security, merely the appearance of it, which is 
counterproductive. What is it exactly you're trying to do?

(Incidentally, a well-written program shouldn't *know* any passwords. It 
should keep one-way hashes instead. This means that no security hole can 
cause the passwords to be revealed. But that's an entirely different 
issue...)

-- 
+- David Given --McQ-+ "`Aplysia californica' is your taxonomic
|  dg@cowlark.com    | nomenclature.
| (dg@tao-group.com) | A slug, by any other name, is still a slug by
+- www.cowlark.com --+ nature." --- drushel on a.f.c