This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should validate when password strength passes', function () { | |
var user = new User({ name: 'Test', username: 'Test', password: 'Test@123' }); | |
user.validate(); | |
assert.isUndefined(user.errors); | |
}); | |
it('should invalidate when password strength fails', function () { | |
var user = new User({ name: 'Test', username: 'Test', password: '1234' }); | |
user.validate(); | |
assert.isDefined(user.errors.password); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check password strength using OWASP module | |
UserSchema | |
.pre('validate', function (next) { | |
// Set options | |
owasp.config(config.password); | |
var result = owasp.test(this.password); | |
if (result.errors.length) { | |
// Join all errors in the array so only one error is returned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UserSchema = new Schema({ | |
name: { type: String, required: true }, | |
username: { type: String, required: true, index: { unique: true } }, | |
email: String, | |
role: { | |
type: String, | |
default: 'User' | |
}, | |
password: { type: String, required: true } | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AutoFacConfig | |
{ | |
public static void Initialize(HttpConfiguration config) | |
{ | |
Initialize(config, RegisterServices(new ContainerBuilder())); | |
} | |
public static void Initialize(HttpConfiguration config, IContainer container) | |
{ | |
config.DependencyResolver = new AutofacWebApiDependencyResolver(container); |