3 var env = require('gitter-web-env');
4 var config = env.config;
5 var crypto = require('crypto');
7 var secret = config.get('web:messageSecret');
9 function validate(unvalidatedMessage, check, defaultMessage) {
10 if (!unvalidatedMessage || !check) {
11 return defaultMessage;
14 unvalidatedMessage = String(unvalidatedMessage);
15 check = String(check);
16 var p = check.split(':');
18 return defaultMessage;
24 var calculatedCheck = crypto
26 .update(secret + salt + unvalidatedMessage, 'utf8')
29 if (calculatedCheck === checksum) {
30 return unvalidatedMessage;
33 return defaultMessage;
36 function getCheck(message) {
37 if (!message) return '';
39 var salt = crypto.randomBytes(6).toString('base64');
43 .update(secret + salt + message, 'utf8')
46 return check + ':' + salt;