1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-10 09:20:26 +00:00
TiddlyWiki5/plugins/tiddlywiki/multiwikiserver/auth/authentication.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

/*\
title: $:/plugins/tiddlywiki/multiwikiserver/auth/authentication.js
type: application/javascript
module-type: library
Handles authentication related operations
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var crypto = require("crypto");
function Authenticator(database) {
if(!(this instanceof Authenticator)) {
return new Authenticator(database);
}
this.sqlTiddlerDatabase = database;
}
Authenticator.prototype.verifyPassword = function(inputPassword, storedHash) {
var hashedInput = this.hashPassword(inputPassword);
return hashedInput === storedHash;
};
Authenticator.prototype.hashPassword = function(password) {
return crypto.createHash("sha256").update(password).digest("hex");
};
Authenticator.prototype.createSession = function(userId) {
var sessionId = crypto.randomBytes(16).toString("hex");
// Store the session in your database or in-memory store
this.sqlTiddlerDatabase.createOrUpdateUserSession(userId, sessionId);
return sessionId;
};
exports.Authenticator = Authenticator;
})();