<commit_before>/*
 * security.cpp
 *   Security related functions
 *   ____            _
 *  |  _ \ ___  __ _| |_ __ ___  ___ 
 *  | |_) / _ \/ _` | | '_ ` _ \/ __|
 *  |  _ <  __/ (_| | | | | | | \__ \
 *  |_| \_\___|\__,_|_|_| |_| |_|___/
 *
 * Permission to use, modify and distribute is granted via the
 *  GNU Affero General Public License v3 or later
 *  
 *  Copyright (C) 2007-2016 <NAME>, <NAME>
 *     Contributions by <NAME>, <NAME>
 *  Based on Mordor (C) <NAME>, <NAME>, <NAME>
 *
 */

#include "creatures.h"
#include "mud.h"
#include "login.h"
#include "server.h"
#include "socket.h"

bstring Player::hashPassword(bstring pass) {
    // implement md5 or sha1 here if you want 
    return(pass);
}

bstring Player::getPassword() const {
    return(password);
}

bool Player::isPassword(bstring pass) const {
    return(password == hashPassword(pass));
}

void Player::setPassword(bstring pass) {
    lastPassword = password;
    password = hashPassword(pass);
}

const char *passCriteria =
    "Passwords must meet the following criteria:\n"
    "1) Must be from %d to %d characters in length.\n"
    "2) Must contain at least 2 letters.\n"
    "3) Must contain at least 2 numbers or special characters.\n"
    "4) Must contain no leading or trailing spaces.\n";


bool isValidPassword(Socket* sock, bstring pass) {
    int         len=0, alpha=0, i=0, digits=0, special=0;

    if(!sock)
        return(false);

    len = pass.length();

    if(pass[0] == ' ') {
        sock->print("No leading spaces allowed.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    if(pass[len-1] == ' ') {
        sock->print("No trailing spaces allowed.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    if(len < PASSWORD_MIN_LENGTH) {
        sock->print("Too short.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    if(len > PASSWORD_MAX_LENGTH) {
        sock->print("Too long.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    for(i=0; i<len; i++) {
        if(isalpha(pass[i]))<commit_msg>fix derp in password check<commit_after>/*
 * security.cpp
 *   Security related functions
 *   ____            _
 *  |  _ \ ___  __ _| |_ __ ___  ___ 
 *  | |_) / _ \/ _` | | '_ ` _ \/ __|
 *  |  _ <  __/ (_| | | | | | | \__ \
 *  |_| \_\___|\__,_|_|_| |_| |_|___/
 *
 * Permission to use, modify and distribute is granted via the
 *  GNU Affero General Public License v3 or later
 *  
 *  Copyright (C) 2007-2016 <NAME>, <NAME>
 *     Contributions by <NAME>, <NAME>
 *  Based on Mordor (C) <NAME>, <NAME>, <NAME>
 *
 */

#include "creatures.h"
#include "mud.h"
#include "login.h"
#include "server.h"
#include "socket.h"

bstring Player::hashPassword(bstring pass) {
    // implement md5 or sha1 here if you want 
    return(pass);
}

bstring Player::getPassword() const {
    return(password);
}

bool Player::isPassword(bstring pass) const {
    return(password == <PASSWORD>Password(pass));
}

void Player::setPassword(bstring pass) {
    lastPassword = password;
    password = <PASSWORD>(<PASSWORD>);
}

const char *passCriteria =
    "Passwords must meet the following criteria:\n"
    "1) Must be from %d to %d characters in length.\n"
    "2) Must contain at least 2 letters.\n"
    "3) Must contain at least 2 numbers or special characters.\n"
    "4) Must contain no leading or trailing spaces.\n";


bool isValidPassword(Socket* sock, bstring pass) {
    int         len=0, alpha=0, i=0, digits=0, special=0;

    if(!sock)
        return(false);

    len = pass.length();

    if(len < PASSWORD_MIN_LENGTH) {
        sock->print("Too short.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    if(pass[0] == ' ') {
        sock->print("No leading spaces allowed.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    if(pass[len-1] == ' ') {
        sock->print("No trailing spaces allowed.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    if(len > PASSWORD_MAX_LENGTH) {
        sock->print("Too long.\n\n");
        sock->print(passCriteria, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH);
        return(false);
    }

    for(i=0; i<len; i++) {
        if(isalpha(pass[i]))
{'fraction_non_alphanumeric': 0.1504950495049505, 'fraction_numerical': 0.011001100110011002, 'mean_word_length': 2.791492910758966, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 38, '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': '171986', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1542, 'n_words': 353}