uit-authenticator
v1.0.1
Published
Encrypt passwords and authenticate against auth.uit.edu.vn from Node.js.
Maintainers
Readme
uit-authenticator
Dependency-free Node.js helpers for:
- encrypting a UIT password in a reversible format
- decrypting that password later
- logging into
https://auth.uit.edu.vn - returning the profile full name and student ID from
UserProfile.aspx
The root package is Node-only. For browser/Vite projects, import the browser-safe crypto helpers from uit-authenticator/browser.
Install
npm install uit-authenticatorUsage
import {
encryptPassword,
authenticateWithEncryptedPassword,
} from "uit-authenticator";
const secret = process.env.UIT_AUTH_SECRET;
const encryptedPassword = encryptPassword("plain-password", secret);
const profile = await authenticateWithEncryptedPassword({
username: "22520001",
encryptedPassword,
secret,
});
console.log(profile.fullName);
console.log(profile.studentId);If you already have the plain password, use authenticateWithPassword(...) directly.
Browser / Vite
Use the browser subpath if you only need reversible encryption in client code:
import { encryptPassword } from "uit-authenticator/browser";
const encryptedPassword = await encryptPassword("plain-password", "shared-secret");This browser entry uses Web Crypto and emits a v2 payload that the Node decryptPassword(...) helper can read. The root package remains Node-only because the authentication helpers depend on node:http, node:https, and other server APIs.
API
encryptPassword(password, secret)
Encrypts the password with AES-256-GCM and returns a compact string.
decryptPassword(encryptedPassword, secret)
Decrypts a string produced by the Node encryptPassword(...) helper or the browser uit-authenticator/browser helper.
authenticateWithEncryptedPassword(options)
Accepts:
usernameencryptedPasswordsecret- optional
loginUrl - optional
profilePath - optional
timeoutMs - optional
userAgent - optional
rejectUnauthorized
Returns:
{
username,
fullName,
studentId,
loginUrl,
profileUrl,
finalUrl,
profileHtml
}