Skip to content

user.LocalUser

Peter edited this page Aug 23, 2024 · 2 revisions

Class: LocalUser

PeterOS User object. No public constructor.

Constructor: LocalUser(name: string, pass: string, perm: string|table)

Create a new LocalUser with name, password, and permissions.

Warning

CAN RETURN nil if another user with name exits.

Parameters

  • name: string - Username
  • pass: string - Plain-text password
  • perm: string|table - Permissions (if string, placed in table)

Fields

Variable Description
name: string User name
pasH: string Hashed password (SHA-256)
perm: nil|{string: boolean} FILE ONLY permission dictionary
_perm: {string: boolean} PROTECTED User permissions

Instance Functions

Signature Return Description
() LocalUser? Constructor
__init__(name, pass, perm) nil PACKAGE
fromFile(name) LocalUser? Create a new User from file
save() boolean Save user to file
hasPerm(perm) boolean Check if user has permission node, or parent
setPerm(perm, value) boolean Set permission node for user
getHomeDir() string Get user's home directory: /home/username/
checkPass(pass) boolean Check password
setPass(oldPass, newPass) boolean Set the user's password

Detail

Functions

__init__

Queue:__init__(name: string, pass: string, perms: {string: boolean}): nil

PACKAGE

Initialize a new LocalUser

Parameters

  • name: string - Username
  • pass: string - Plain-text password
  • perms: {string: boolean} - Permission tree

fromFile

Queue:fromFile(name: string): LocalUser?

Create a new User from file

Parameters

  • name: string - Username

Returns

  • user: LocalUser?

save

Queue:save(): boolean

Save user to file

Returns

  • saved: boolean

hasPerm

Queue:hasPerm(perm: string): boolean

Check if user has permission node, or parent

Parameters

  • perm: string - Permission node

Returns

  • hasPerm: boolean - Description

setPerm

Queue:setPerm(perm: string, value: true|false|nil): boolean

Set permission node for user

Parameters

  • perm: string - Permission node
  • value: true|false|nil - Permission status. true for has, false for block, nil to unset

Returns

  • saved: boolean - If the change could be saved

getHomeDir

Queue:getHomeDir(): string

Get user's home directory: /home/username/

Returns

  • homeDir: string

checkPass

Queue:checkPass(pass: string): boolean

Check password

Parameters

  • pass: string - Password to check

Returns

  • valid: boolean

setPass

Queue:setPass(oldPass: string, newPass: string): boolean

Set the user's password

Parameters

  • oldPass: string - Current password
  • newPass: string - New password

Returns

  • set: boolean