File: passwordmaker.cpp

package info (click to toggle)
passwordmaker-cli 1.5%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 636 kB
  • sloc: cpp: 6,768; makefile: 29
file content (95 lines) | stat: -rwxr-xr-x 3,007 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * PasswordMaker - Creates and manages passwords
 * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc.
 * http://passwordmaker.org/
 * grimholtz@yahoo.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * Written by Miquel Burns <miquelfire@gmail.com> and Eric H. Jung
*/

#include "stdafx.h"
#include "passwordmaker.h"
#include "shared/hasher.h"
#include "leet.h"

using namespace std;

char base93Set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./";

PasswordMaker::PasswordMaker(void)
{
	hasher = new Hasher;
}

PasswordMaker::~PasswordMaker(void)
{
	delete hasher; // Don't what a memory leak
}

bool PasswordMaker::initialized() {
	return hasher->initialized();
}

void PasswordMaker::setPath(string path) {
	if (!hasher->initialized()) {
		delete hasher;
		hasher = new Hasher(path);
	}
}

string PasswordMaker::generatePassword(std::string masterPassword,
	hashType algorithm, bool hmac, bool trim, std::string url, int length,
	std::string characters, leetType useLeet, int leetLevel,
	std::string username, std::string modifier, std::string prefix,
	std::string suffix, bool sha256_bug)
{
	string data, password = "";
	int count = 0;

	
	leetLevel--;
	data = url + username + modifier;
	// Never *ever, ever* allow the character set length < 2 else
	// the hash algorithms will run indefinitely
	if (characters.length() < 2)
		return "Invalid arguments: the minimum number of characters is two.";

	if (useLeet == LEET_BEFORE || useLeet == LEET_BOTH) {
		masterPassword = leetConvert(leetLevel, masterPassword);
		data = leetConvert(leetLevel, data);
	}

	while ((int)password.length() < length) {
		char tempvalue[12];
		sprintf(tempvalue, "%i", count);
		if (count == 0) {
			password = hasher->hash(algorithm, hmac, trim, characters, data, masterPassword, sha256_bug);
		} else {
			password += hasher->hash(algorithm, hmac, trim, characters, data, masterPassword+"\n"+tempvalue, sha256_bug);
		}
		count++;
	}

	if (useLeet == LEET_AFTER || useLeet == LEET_BOTH)
		password = leetConvert(leetLevel, password);

	password = prefix + password;
	password = password.substr(0, length-suffix.length()) + suffix;

	return password.substr(0, length);
}