<commit_before>define(function(require) {
    'use strict';

    var appController = require('js/app-controller');

    var LoginInitialCtrl = function($scope, $location) {
        var emailDao = appController._emailDao,
            states, termsMsg = 'You must accept the Terms of Service to continue.';

        states = {
            IDLE: 1,
            SET_PASSPHRASE: 2,
            PROCESSING: 3,
            DONE: 4
        };
        $scope.state.ui = states.IDLE; // initial state

        //
        // scope functions
        //

        $scope.importKey = function() {
            if (!$scope.state.agree) {
                $scope.onError({
                    message: termsMsg
                });
                return;
            }

            $location.path('/login-new-device');
        };

        $scope.setPassphrase = function() {
            if (!$scope.state.agree) {
                $scope.onError({
                    message: termsMsg
                });
                return;
            }

            $scope.setState(states.SET_PASSPHRASE);
        };

        /*
         * Taken from jQuery validate.password plug-in 1.0
         * http://bassistance.de/jquery-plugins/jquery-plugin-validate.password/
         *
         * Copyright (c) 2009 <NAME>
         *
         * Licensed under the MIT
         *   http://www.opensource.org/licenses/mit-license.php
         */
        $scope.checkPassphraseQuality = function() {
            var passphrase = $scope.state.passphrase;
            $scope.passphraseRating = 0;

            var LOWER = /[a-z]/,
                UPPER = /[A-Z]/,
                DIGIT = /[0-9]/,
                DIGITS = /[0-9].*[0-9]/,
                SPECIAL = /[^a-zA-Z0-9]/,
                SAME = /^(.)\1+$/;

            function uncapitalize(str) {
                return str.substring(0, 1).toLowerCase() + str.substring(1);
            }

            if (!passphrase) {
                // no rating for empty passphrase
                $scope.passphraseMsg = '';
                return;
            }

            if (passphrase.length < 8 || SAME.test(passphrase)) {
                $scope.passphraseMsg = '<PASSWORD>';
                return;
            }

            var lower = LOWER.test(passphrase),
                upper = UPPER.test(uncapitalize(passphrase)),
                digit = DIGIT.test(passphrase),
                digits = DIGITS.test(passphrase),
                special = SPECIAL.test(passphrase);

            if (lower && upper && digit || lower && digits || upper && digits || special) {
                $scope.passphraseMsg = 'Strong';
                $scope.passphraseRating = 3;
            } else if (lower && upper || lower && digit || upper && digit) {
                $scope.passphraseMsg = 'Good';
                $scope.passphraseRating = 2;
            } else {
                $scope.passphraseMsg = '<PASSWORD>';
                $scope.passphraseRating = 1;
            }
        };

        $scope.confirmPassphrase = function() {
            var passphrase = $scope.state.passphrase,
                confirmation = $scope.state.confirmation;

            if (passphrase !== confirmation) {
                return;
            }

            $scope.setState(states.PROCESSING);

            setTimeout(function() {
                emailDao.unlock({
                    passphrase: (passphrase) ? passphrase : undefined
                }, function(err) {
                    if (err) {
                        $scope.setState(states.SET_PASSPHRASE);
                        $scope.onError(err);
                        return;
                    }

                    appController._auth.storeCredentials(function(err) {<commit_msg>Fix bug where changing passphrase back to empty string blocked keygen<commit_after>define(function(require) {
    'use strict';

    var appController = require('js/app-controller');

    var LoginInitialCtrl = function($scope, $location) {
        var emailDao = appController._emailDao,
            states, termsMsg = 'You must accept the Terms of Service to continue.';

        states = {
            IDLE: 1,
            SET_PASSPHRASE: 2,
            PROCESSING: 3,
            DONE: 4
        };
        $scope.state.ui = states.IDLE; // initial state

        //
        // scope functions
        //

        $scope.importKey = function() {
            if (!$scope.state.agree) {
                $scope.onError({
                    message: termsMsg
                });
                return;
            }

            $location.path('/login-new-device');
        };

        $scope.setPassphrase = function() {
            if (!$scope.state.agree) {
                $scope.onError({
                    message: termsMsg
                });
                return;
            }

            $scope.setState(states.SET_PASSPHRASE);
        };

        /*
         * Taken from jQuery validate.password plug-in 1.0
         * http://bassistance.de/jquery-plugins/jquery-plugin-validate.password/
         *
         * Copyright (c) 2009 <NAME>
         *
         * Licensed under the MIT
         *   http://www.opensource.org/licenses/mit-license.php
         */
        $scope.checkPassphraseQuality = function() {
            var passphrase = $scope.state.passphrase;
            $scope.passphraseRating = 0;

            var LOWER = /[a-z]/,
                UPPER = /[A-Z]/,
                DIGIT = /[0-9]/,
                DIGITS = /[0-9].*[0-9]/,
                SPECIAL = /[^a-zA-Z0-9]/,
                SAME = /^(.)\1+$/;

            function uncapitalize(str) {
                return str.substring(0, 1).toLowerCase() + str.substring(1);
            }

            if (!passphrase) {
                // no rating for empty passphrase
                $scope.passphraseMsg = '';
                return;
            }

            if (passphrase.length < 8 || SAME.test(passphrase)) {
                $scope.passphraseMsg = 'Very weak';
                return;
            }

            var lower = LOWER.test(passphrase),
                upper = UPPER.test(uncapitalize(passphrase)),
                digit = DIGIT.test(passphrase),
                digits = DIGITS.test(passphrase),
                special = SPECIAL.test(passphrase);

            if (lower && upper && digit || lower && digits || upper && digits || special) {
                $scope.passphraseMsg = 'Strong';
                $scope.passphraseRating = 3;
            } else if (lower && upper || lower && digit || upper && digit) {
                $scope.passphraseMsg = 'Good';
                $scope.passphraseRating = 2;
            } else {
                $scope.passphraseMsg = 'Weak';
                $scope.passphraseRating = 1;
            }
        };

        $scope.confirmPassphrase = function() {
            var passphrase = $scope.state.passphrase;

            $scope.setState(states.PROCESSING);

            setTimeout(function() {
                emailDao.unlock({
                    passphrase: (passphrase) ? passphrase : undefined
                }, function(err) {
                    if (err) {
                        $scope.setState(states.SET_PASSPHRASE);
                        $scope.onError(err);
                        return;
                    }

                    appController._auth.storeCredentials(function(err) {
{'fraction_non_alphanumeric': 0.11845133342358197, 'fraction_numerical': 0.007310139434141058, 'mean_word_length': 1.2517525144772934, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5812393', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1899, 'n_words': 367}