Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9583048
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/base-chips/field_type.hashed-text.js b/lib/base-chips/field_type.hashed-text.js
index b57723f1..f40dff62 100644
--- a/lib/base-chips/field_type.hashed-text.js
+++ b/lib/base-chips/field_type.hashed-text.js
@@ -1,47 +1,47 @@
var Sealious = require('../main.js');
var Promise = require("bluebird");
var crypto = require("crypto");
var field_type_hashed_text = new Sealious.ChipTypes.FieldType({
name: "hashed-text",
extends: "text",
get_description: function(context, params){
return "Hash passwords with chosen algorithm (default md5)";
},
is_proper_value: function(accept, reject, context, params, new_value){
if (params === undefined)
accept();
- else if (params.numbers !== undefined){
+ else if (params.numbers !== undefined && params.capitals === undefined){
var pattern = new RegExp("(.*[0-9]+.*){" + params.numbers + "}");
pattern.test(new_value) ? accept() : reject("Doesn't match");
}
- else if (params.capitals !== undefined){
+ else if (params.capitals !== undefined && params.numbers === undefined){
var pattern = new RegExp("(.*[A-Z]+.*){" + params.capitals + "}");
pattern.test(new_value) ? accept() : reject();
}
- else if (params.number !== undefined && params.capitals !== undefine){
+ else if (params.numbers !== undefined && params.capitals !== undefined){
var pattern1 = new RegExp("(.*[0-9]+.*){" + params.numbers + "}");
var pattern2 = new RegExp("(.*[A-Z]+.*){" + params.capitals + "}");
if (pattern1.test(new_value) && pattern2.test(new_value))
accept();
else
reject("Doesn't match")
}
},
encode: function(context, params, value_in_code){
var salt, algorithm;
if (params !== undefined) {
salt = params.salt || "";
algorithm = params.algorithm || "md5";
}
return new Promise(function(resolve, reject) {
crypto.pbkdf2(value_in_code, salt, 4096, 64, algorithm, function(err, key){
if (err)
reject(err)
resolve(key.toString('hex'));
});
})
}
})
diff --git a/tests/unit-tests/field-type.hashed-text.test.js b/tests/unit-tests/field-type.hashed-text.test.js
index 30bc9259..2faf3451 100644
--- a/tests/unit-tests/field-type.hashed-text.test.js
+++ b/tests/unit-tests/field-type.hashed-text.test.js
@@ -1,63 +1,63 @@
var Sealious = require("sealious");
var crypto = require('crypto');
module.exports = {
test_init: function() {
},
test_start: function() {
var field_type_hashed_text = Sealious.ChipManager.get_chip("field_type", "hashed-text");
describe("FieldType.HashedText", function() {
it("should return the description of the field type", function(done) {
if (typeof field_type_hashed_text.declaration.get_description() === "string")
done();
else
done(new Error("But it didn't"));
});
it("accepts given password ('pas1sw24rd1')", function(done) {
field_type_hashed_text.is_proper_value(new Sealious.Context(), {numbers: 3}, "pas1sw24rd1")
.then(function() {
done();
})
.catch(function(error) {
done(new Error(error));
})
});
it("accepts given password ('PAs1sW24rD1')", function(done) {
field_type_hashed_text.is_proper_value(new Sealious.Context(), {capitals: 3}, "PAs1sW24rD1")
.then(function() {
done();
})
.catch(function(error) {
done(new Error(error));
})
});
it("accepts given password ('PaSw0rd23')", function(done) {
- field_type_hashed_text.is_proper_value(new Sealious.Context(), {capitals: 2, number: 3}, "PaSw0rd23")
+ field_type_hashed_text.is_proper_value(new Sealious.Context(), {capitals: 2, numbers: 3}, "PaSw0rd23")
.then(function() {
done();
})
.catch(function(error) {
done(new Error(error));
})
});
it("resolved with a hash (algorithm: 'md5', salt: '')", function(done) {
field_type_hashed_text.encode(new Sealious.Context(), {}, "test")
.then(function(result){
crypto.pbkdf2("test", "", 4096, 64, "md5", function(err, key){
if (err)
done(new Error(err));
if (key.toString('hex') === result)
done();
else
done(new Error("Wrong hash"))
});
})
.catch(function(error){
done(new Error(error))
})
})
})
}
}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 11, 08:36 (11 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
981712
Default Alt Text
(4 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment