A simple auth library for the authentication of users in web apps or APIs
Developed By MrShoe_
To install elementary-auth use this command:
npm install elementary-auth
To use the library you first need to initalise the authentication object
const authenticationManager = require('elementary-auth')
const authManager = new authenticationManager(
encryption_key,
salt
)
The encryption_key is used to encrypt and protect your users password for you so you dont need to encrypt the data yourself
and the salt is used to help protect the password so that any hacker cant brute force any passwords and help keep them protected
Here is how you can create a user
authManager.createUser(
username,
password,
other
)
The username and password are obvious, but the other item is used to store data for or about the user. For example, you can store things like settings or user role
Return Value:
return {
username: usernname,
password: encrypted_password,
data, other
}
See if a username is valid
authManager.checkUser(
username,
password,
other
)
Return Value:
return
true
||
false
Gets the user object bassed on username
authManager.getUser(username)
Return Value:
return {
username: usernname,
password: encrypted_password,
data, other
}
This simply checks the users password and verifys if they entered the correct password
authManager.verifyUser(username, password)
this simply returns a true/false value
Deletes a user bassed on the username
authManager.deleteUser(username)
Simply changes the users password bassed on the username
authManager.changePassword(username, newPassword)
Tokens are normaly used for authentication in web apps and can be stored in the cookies or as JWT on the client or browser
Create token generates a 50000 long string uniqe to there user sesson
authManager.createToken(username)
and this returns the token for the user
Check and verify the token for a user
authManager.checkToken(token)
Return Value:
return
[true, username] // If token is valid
||
[false, undefined] // if token is invalid
Simply removes a token from being usable
authManager.deleteToken(token)
This simply imports and exports the auth data with the .importData()
and .exportData()
functions to be stored in a database or other location
if you would like to store your data, we would recomend using a package we also developed, elementary-db a simple database for storing json data