Skip to content

Locks & doors ​

A lock is anything that asks for a secret: a door keypad, a safe, a stash, a laptop, a vehicle ignition, a Wi-Fi network. Locks live in np_passwords. The code is stored only as a bcrypt hash (GetPasswordHash) and compared on the server (VerifyPasswordHash); it never goes to a client and never to the resource that registered the lock.

What a character knows is separate: their keychain holds the codes they typed, saved, were given or read on a note, encrypted per character. A keychain entry can be outdated (the owner changed the code), and that is roleplay.

Lock types ​

type Secret Prompt
pin Digits. length 1–12 (fixed when set) Dots and a 3×4 keypad, number keys work
password Any printable text, 1–64 characters One masked field with an eye toggle
login A password plus a username (username = 'admin' pins the expected one) User and password fields with a dropdown of saved logins
phrase Lowercase words joined by - (grove-taco-lamp-42), easy to say over the radio Word chips
pattern Dot indices 1–9 as a string ("1259"), no repeats, at least 4 3×3 dot grid

2FA codes (otp) are not locks; see 2FA codes.

Register a lock ​

server

lua
local ok, err = exports.np_passwords:RegisterLock({
  id = 'apt12:front',               -- unique, up to 64 characters
  label = 'Apartment 12 · front',
  icon = 'door-closed',             -- Font Awesome name without fa-
  type = 'pin', length = 4,
  owner = { type = 'char', id = cid },
  coords = vector3(-1150.2, -1520.4, 10.6), radius = 1.5,
  tries = 3, lockout = 60,
  generate = true,
  door = { model = `v_ilev_fa_frontdoor`, coords = vector3(-1150.6, -1520.9, 10.6), autoRelock = 8 },
  meta = { sub = 'Integrity Way · 4 digits' },
})

RegisterLock is idempotent: call it at every start. The lock is saved in np_pw_locks and loaded again after a restart. Calling it again updates label, owner, coords and the rest, but keeps the existing code unless you pass reset = true.

Field Default Description
id required Unique id. Prefix it with your resource or place (apt12:safe, veh:4KX92). stash: and gangstash: are reserved
label id Title of the prompt and the keychain entry
icon 'lock' Font Awesome icon name
type 'pin' See Lock types
length – PIN length (1–12). Codes of another length are refused
rules {} { min, max, words, digit, symbol, upper, noReuse }: rules for new codes in the generator
owner { type = 'none' } See Owners
coords, radius – / Config.Locks.radius Position of the lock. Without coords there is no proximity prompt and no distance check
tries, lockout 3 / 45 Wrong tries before a lockout, lockout seconds
notifyOwner true Alert owners on lockouts and leaks
dispatch false Fire np_passwords:dispatch on a lockout
autofill true false: saved codes never fill here, the player always types
crackable true false: the code breaker refuses this lock
code – Initial code. Ignored when the lock already has one, unless reset = true
generate false Random code when the lock has none. It is saved to the owner's keychain (or their vault)
door – { model, coords, heading?, autoRelock? } or a list of up to 8 parts (double doors, gates); more refuse the lock (too_many_door_parts). See Doors
username – login locks: the username that must match
meta {} Free data. Read by np_passwords: sub (second line of the prompt and the app entry), tint, prop (keypad model, an np_prophandler prop np_passwords:<lockId> at coords)
persist true false: in memory only, gone after a restart (register it again on start)

Errors: invalid_id, invalid_label, invalid_type, invalid_length, invalid_owner, invalid_code, invalid.

Remove a lock with RemoveLock(id). GetLock(id) returns its public info (never the hash): type, owner, tries, fails, lockout end, strength, leaked flag, codeSetAt, rules, meta. See Exports.

Static locks in the config ​

Locks that belong to the map (police evidence room, bank vault) can go in Config.Locks.static, with the same fields. They are registered at every start:

lua
Config.Locks.static = {
  { id = 'pd:evidence', label = 'Evidence room', icon = 'box-archive', type = 'pin', length = 6,
    owner = { type = 'job', id = 'police', grade = 3 }, coords = vector3(474.5, -990.3, 26.3),
    generate = true, door = { model = `v_ilev_ph_gendoor002`, coords = vector3(474.9, -990.5, 26.3), autoRelock = 10 } },
}

Owners ​

The owner decides who manages a lock: changes the code, creates guest codes, gets alerts. Owning a lock does not mean knowing its code; that is what the keychain is for.

owner.type owner.id Manages
char Character id (citizenid / identifier) That character
job Job name Members of the job with grade or higher, and the boss
gang np_gangs gang id Members with rank grade or higher (default 3 = og)
vault Vault id Vault members who may manage it
none – Nobody (only staff)

Staff with the node np_passwords.locks manage every lock.

Insiders (the owner, colleagues of the same job or gang, members of the owning vault) never trigger a leak when they type the code.

Codes, grants and guest codes ​

server

lua
-- rotate (vault items of this lock get the new code; other keychains go stale)
exports.np_passwords:SetCode('pd:evidence', '904417')

-- give a player, a job, a gang or a vault the code
exports.np_passwords:Grant('apt12:front', source)          -- server id
exports.np_passwords:Grant('apt12:front', 'ABC12345')      -- character id (works offline)
exports.np_passwords:Grant('pd:evidence', 'job:police')    -- job vault
exports.np_passwords:Grant('grove:garage', 'gang:3')       -- gang vault
exports.np_passwords:Revoke('apt12:front', 'ABC12345')

-- ask the player to save the code (secret optional when np_passwords knows it)
exports.np_passwords:OfferSave(source, 'apt12:front')

np_passwords only knows a plain code in memory after it set it (SetCode, generate, code) or after someone typed it correctly since the last restart. Without a known code, Grant still adds a keychain entry: it works as a key (autofill opens the lock) but has no code to reveal or share. OfferSave without a secret returns false then.

When a code changes, every keychain entry saved before is stale: autofill fails, and the app shows it as outdated. Vault items of the lock get the new code automatically.

Guest codes ​

lua
local code = exports.np_passwords:GuestCode('apt12:front', { uses = 1, ttl = 7200, label = 'Delivery' })

A random extra code of the lock's type (PINs get the lock's length). It opens the lock uses times (1–25) within ttl seconds (60 s to 7 days, default 2 h) and is then deleted. Owners create guest codes in the phone app too. A guest unlock counts as method guest and is not a leak.

Doors ​

A lock with door keeps a door state on the server, locked by default. A successful unlock opens the door for everyone; autoRelock (seconds, from the first door entry) locks it again. All entries together are one np_prophandler door np_passwords:door:<lockId> with up to 8 parts (registerDoor, setDoorLocked), registered on the server and again on np_prophandler:ready, so no door resource is needed.

With np_doors the other way round works too: an np_doors door with pin = { provider = 'np_passwords', lock = '<lock id>' } asks np_passwords for the code (Prompt, ConsumeUnlock) instead of its own keypad (np_doors lock types). Give that lock no door of its own, so the door is only registered once.

lua
door = {
  { model = `v_ilev_ph_door01`, coords = vector3(434.7, -980.6, 30.8) },
  { model = `v_ilev_ph_door002`, coords = vector3(434.7, -983.2, 30.8), autoRelock = 6 },
}

model is a hash or a model name. Players who know the code (or manage the lock) get E Lock at an open door. Set the state from your script with SetDoorState(id, locked). Turn doors off entirely with Config.Doors.enabled = false.

Stash locks ​

With np_inventory (or ox_inventory), a lock whose id is stash:<stashId> guards that stash. np_passwords registers a beforeOpen hook: opening the stash is refused, the prompt opens instead, and on success the stash opens.

lua
-- server: the stash 'house_42' (np_inventory) now asks for a code
exports.np_passwords:RegisterLock({
  id = 'stash:house_42', label = 'Wardrobe safe', icon = 'vault', type = 'pin', length = 4,
  owner = { type = 'char', id = ownerCid }, generate = true,
})
  • Locks without a code don't block the stash.
  • The stash needs no pin of its own in np_inventory; leave its groups / owner as they are, they still apply.
  • The prefix is Config.Stash.prefix; switch the feature off with Config.Stash.enabled = false.
  • qb-inventory has no stash hooks, so stash locks need np_inventory or ox_inventory.

Gang stash lock ​

Opt-in with Config.Gangs.stashLock = true. The first time a gang opens its np_gangs stash, np_passwords creates the lock gangstash:<gangId> (4-digit PIN, owned by the gang, rank 3 manages) without a code, so the stash stays open. Once a code is set (an og through Create, or your script with SetCode), every member is asked for it before the stash opens. Share it through the gang vault with Grant('gangstash:<gangId>', 'gang:<gangId>').

Admin commands ​

/pwlock (node np_passwords.locks) places quick locks for testing or events:

Command What
/pwlock add <type> <label…> [code] Lock at your position, id admin:<n>, owner none. Without a code a random one is generated and shown. A PIN without a code has 4 digits
/pwlock remove <id> Remove a lock
/pwlock reset <id> Clear lockout, fail counter and the leak flag
/pwlock list Up to 15 locks, nearest first

For password, login and phrase locks the last argument is read as the code whenever it is a valid code of that type, so always pass one. See Events & commands for the np_admin staff actions.