Methods
# generatePassword(lengthopt) → {string}
Generates a strong password with a combination of letters, numbers, and symbols.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
length |
number
|
<optional> |
12 | Length of the generated password. |
The generated password.
string
Example
import generatePassword from './generatePassword.js';
const myPassword = generatePassword(16);
console.log(myPassword); // Example output: 'aB3!xD@eFg#1$hIj'
# hashPassword(password, salt, iterations) → {Promise.<string>}
Hashes a password using a salt and a specified number of iterations.
Parameters:
Name | Type | Description |
---|---|---|
password |
string
|
The plain text password to hash. |
salt |
string
|
The salt value to use during hashing. |
iterations |
number
|
The number of hashing iterations. |
If an error occurs during hashing.
Error
A promise that resolves to the hashed password as a hexadecimal string.
Promise.<string>
Example
import hashPassword from './hashPassword.js';
async function example() {
const password = 'mypassword';
const salt = 'randomSaltValue';
const iterations = 1000;
try {
const hashedPassword = await hashPassword(password, salt, iterations);
console.log(hashedPassword); // Logs the hashed password
} catch (error) {
console.error('Error hashing password:', error.message);
}
}
example();
# me(options) → {function}
.me: Handles identity logging and context establishment for space, user, and event requests.
Logs the identity in the ledger on the provided port and v.path URL.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
Object
|
Configuration options | ||
ledger |
string
|
The ledger API endpoint (v.path URL) | ||
jwtCookieName |
string
|
<optional> |
'jwt' | The name of the JWT cookie to use for user identity |
requireAuth |
boolean
|
<optional> |
false | Set to true if user authentication is required |
Express middleware for handling space, request, and user identity.
function
# passwordSecurityCheck(password) → {boolean}
Checks if a password meets basic security criteria.
Criteria: At least 8 characters, includes uppercase, lowercase, number, and special character.
Parameters:
Name | Type | Description |
---|---|---|
password |
string
|
The password to check. |
True if the password is secure, false otherwise.
boolean
Example
import passwordSecurityCheck from './passwordSecurityCheck.js';
const isSecure = passwordSecurityCheck('aB3!xD@e');
console.log(isSecure); // Example output: true
# randomToken(lengthopt) → {string}
Generates a random token (e.g., for verification purposes).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
length |
number
|
<optional> |
20 | The length of the token in bytes. |
A randomly generated token in hexadecimal format.
string
Example
import randomToken from './randomToken.js';
const token = randomToken(16);
console.log(token); // Example output: '9f86d081884c7d659a2feaa0c55ad015'
# salt(lengthopt) → {string}
Generates a cryptographic salt for secure operations (e.g., password hashing).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
length |
number
|
<optional> |
16 | The desired length of the salt in bytes. |
A randomly generated salt in hexadecimal format.
string
Example
import salt from './salt.js';
const mySalt = salt(16);
console.log(mySalt); // Example output: 'e3b0c44298fc1c14'
# validateEmail(email) → {string}
Validates an email address to ensure it follows correct syntax.
Parameters:
Name | Type | Description |
---|---|---|
email |
string
|
The email to validate. |
If the email is invalid.
Error
The valid email if it passes validation.
string
# validateUsername(username) → {string}
Validates a username to ensure it meets specific rules.
Parameters:
Name | Type | Description |
---|---|---|
username |
string
|
The username to validate. |
If the username does not meet the criteria.
Error
The valid username if it passes validation.
string
# async verifyPassword(password, hashedPassword, salt, iterationsopt) → {Promise.<boolean>}
Verifies if a password matches a stored hash using a secure timing-safe comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
password |
string
|
Plain text password. | ||
hashedPassword |
string
|
Stored hashed password. | ||
salt |
string
|
Salt used during hashing. | ||
iterations |
number
|
<optional> |
1000 | Iterations used for hashing. |
True if the password is valid, false otherwise.
Promise.<boolean>