<commit_before>/**
  * @module viewmodels/ValidatedPassword
  */
'use strict';

var ko = require('knockout'),
    PasswordValidator = require('../utils/PasswordValidator'),
    Field = require('./Field');

/*
 * View model representing a password field with validation and messages.
 * 
 * The password value is a Field 
 * @class
 */
function ValidatedPassword() {
    /**
      * password is the value of the password field
      *
      * @public
      */
    this.password = new Field();
    this.showRequirements = ko.observable(false);
    this.showRequirementsLink = ko.observable(true);

    /**
     * @public
     */
    this.reset = function() {
        this.showRequirements(false);
        this.showRequirementsLink(true);
        this.password('');
    };

    this.requirementsLinkClick = function() {
        this.showRequirements(true);
    }.bind(this);

    this.fieldFocus = function() {
        this.showRequirements(true);
        this.showRequirementsLink(false);
    }.bind(this);

    /**
      * @private
      */ 
    this.validator = ko.pureComputed(function() {
        return new PasswordValidator(this.password());
    }, this);

    this.isValid = ko.pureComputed(function() {
        return this.validator().isValid();
    }, this);

    this.isLengthValid = ko.pureComputed(function() {
        return this.validator().isCorrectLength();
    }, this);

    this.isCharacterKindsValid = ko.pureComputed(function() {
        return this.validator().isCorrectCharacterKinds();
    }, this);

    this.usesSymbol = ko.pureComputed(function() {
        return this.validator().isCorrectSymbol();
    }, this);

    this.usesUpper = ko.pureComputed(function() {
        return this.validator().isCorrectUpper();
    }, this);

    this.usesLower = ko.pureComputed(function() {
        return this.validator().isCorrectLower();
    }, this);

    this.usesNumber = ko.pureComputed(function() {
        return this.validator().isCorrectNumber();
    }, this);

    this.characterKindsLabel = ko.pureComputed(function() {
        var count = this.validator().isCorrectCharacterKindsCount(),
            labels = [
                    'Includes at least 3 kinds of characters:',
                    'Includes at least 2 more kinds of characters:',
                    'Includes at least 1 more kind of character:',
                    'Includes at least 3 kinds of characters'
                ];
        return labels[Math.min(count, labels.length - 1)];
    }, this);
}

module.exports = ValidatedPassword;
<commit_msg>changed labels for password validation #318<commit_after>/**
  * @module viewmodels/ValidatedPassword
  */
'use strict';

var ko = require('knockout'),
    PasswordValidator = require('../utils/PasswordValidator'),
    Field = require('./Field');

/*
 * View model representing a password field with validation and messages.
 * 
 * The password value is a Field 
 * @class
 */
function ValidatedPassword() {
    /**
      * password is the value of the password field
      *
      * @public
      */
    this.password = new Field();
    this.showRequirements = ko.observable(false);
    this.showRequirementsLink = ko.observable(true);

    /**
     * @public
     */
    this.reset = function() {
        this.showRequirements(false);
        this.showRequirementsLink(true);
        this.password('');
    };

    this.requirementsLinkClick = function() {
        this.showRequirements(true);
    }.bind(this);

    this.fieldFocus = function() {
        this.showRequirements(true);
        this.showRequirementsLink(false);
    }.bind(this);

    /**
      * @private
      */ 
    this.validator = ko.pureComputed(function() {
        return new PasswordValidator(this.password());
    }, this);

    this.isValid = ko.pureComputed(function() {
        return this.validator().isValid();
    }, this);

    this.isLengthValid = ko.pureComputed(function() {
        return this.validator().isCorrectLength();
    }, this);

    this.isCharacterKindsValid = ko.pureComputed(function() {
        return this.validator().isCorrectCharacterKinds();
    }, this);

    this.usesSymbol = ko.pureComputed(function() {
        return this.validator().isCorrectSymbol();
    }, this);

    this.usesUpper = ko.pureComputed(function() {
        return this.validator().isCorrectUpper();
    }, this);

    this.usesLower = ko.pureComputed(function() {
        return this.validator().isCorrectLower();
    }, this);

    this.usesNumber = ko.pureComputed(function() {
        return this.validator().isCorrectNumber();
    }, this);

    this.characterKindsLabel = ko.pureComputed(function() {
        var count = this.validator().isCorrectCharacterKindsCount(),
            labels = [
                    'Includes at least 3 character types:',
                    'Includes at least 2 more character types:',
                    'Includes at least 1 more character type:',
                    'Includes at least 3 character types'
                ];
        return labels[Math.min(count, labels.length - 1)];
    }, this);
}

module.exports = ValidatedPassword;

{'fraction_non_alphanumeric': 0.13227513227513227, 'fraction_numerical': 0.0025475210660395845, 'mean_word_length': 2.52, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2484926', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1384, 'n_words': 295}