Skip to content

Web components ​

Resources with their own NUI (a laptop, an MDT, a banking site) don't have to open np_passwords' panel on top. They drop np_passwords' web components into their page instead: a password field with autofill, a new-password field with the generator, and a 2FA field. The host page never gets the secret.

  • <np-password>: unlock a lock or sign in through a verifier
  • <np-password-new>: choose a new code with generator, strength and rules
  • <np-otp>: enter a 2FA code

They come in the Nimbus UI look (Quicksand, grey glass, squircle tiles) with the tokens inlined, so they look the same on any host page.

Load the module ​

html
<script type="module" src="https://cfx-nui-np_passwords/web/dist/components/np-pw.js"></script>

np-pw.js is one ES module without dependencies, built by npm run build in np_passwords' web/. It registers the three custom elements. The components talk to np_passwords directly with fetch('https://np_passwords/component.*') (cross-resource NUI fetch), so the host needs no Lua glue.

<np-password> ​

html
<!-- a registered lock -->
<np-password lock="laptop:ceo"></np-password>

<!-- an account your resource keeps (RegisterVerifier('mdt', fn) on the server) -->
<np-password verify="mdt" username="ofc.pearce"></np-password>
Attribute Description
lock Lock id
verify Verifier name (instead of lock)
username Pre-filled username. Its presence (or verify) makes it a login
type pin, password or login. Default: login with verify / username, else password
lang en or de (else the closest lang attribute up the tree, else English)

Saved entries show as chips above the field: Use saved code for locks, or the saved logins (own first, then shared, with the vault name). TAB uses the highlighted one, ↑ ↓ pick another; a saved code submits right away, a saved login on ENTER. ENTER submits what was typed, ESC fires np-cancel. Wrong codes show n tries left, a locked-out lock shows Locked.

js
document.querySelector('np-password').addEventListener('np-unlock', async (e) => {
  if (!e.detail.ok) return
  // tell your Lua; your server checks ConsumeUnlock(source, 'laptop:ceo') or ('verify:mdt')
  await fetch(`https://${GetParentResourceName()}/signedIn`, { method: 'POST', body: '{}' })
})

<np-password-new> ​

html
<form id="signup">
  <np-password-new type="password" rules="min:10,digit,upper"></np-password-new>
  <button>Create account</button>
</form>
Attribute Description
type password (default), pin or phrase
rules min:10,digit,upper style: min, max, words, digit, symbol, upper (comma or space separated)
lock Optional lock id: set that lock's code (owners, managers and staff only)
lang en or de

The field starts with a generated suggestion (the wand shuffles), shows the strength as time to crack and lists the rules that still fail. Submitting the surrounding <form>, ENTER, or calling el.submit() (returns a promise of true / false) sends it to np_passwords.

  • With lock: the server checks that the player manages the lock, validates the rules, sets the code (the creator's keychain gets it) and answers with the strength.
  • Without lock: the server only validates format and rules and answers the strength. Nothing is stored. Use it for a new account in your own resource, then let the player save it through a verifier login.

Then np-created fires with { strength: { level, seconds } }.

<np-otp> ​

html
<np-otp app="mazebank"></np-otp>
Attribute Description
app 2FA app id (Config.Otp.apps or RegisterOtpApp)
lang en or de

Six boxes; the code submits when the sixth digit is in. The chip Use code from Passwords (with the seconds left) only shows once the player is enrolled and fills the code on the server with TAB. The first prompt enrols the player and texts the code, like RequireCode. On success your server sees IsUnlocked(src, 'otp:mazebank').

Events ​

All events bubble and are composed (they cross the shadow root into your page).

Event Detail When
np-unlock { ok } After every submit of <np-password> / <np-otp>. ok = true means np_passwords recorded the unlock
np-created { strength: { level, seconds } } <np-password-new> was accepted
np-cancel – ESC inside a component

Security ​

  • Shadow roots are closed: the host can't reach into them, and the secret is never written to an attribute, a property or an event. It only travels in the fetch body to https://np_passwords/component.*.
  • Autofill sends only the entry id; np_passwords decrypts and compares on the server.
  • The page's np-unlock is a hint for the UI. Act on the server with ConsumeUnlock / IsUnlocked: the record ids are the lock id, verify:<name> or otp:<app>.
  • Distance, lockout, tries and rate limits apply exactly as in np_passwords' own prompt.

The NUI callbacks behind the components are listed in the NUI contract.