Monthly Archives: April 2014

 

Assignment #5 – Climate Change
Global Warming/ Climate change project
Input: weather data for months of several years – tab delimited file – average temperature for the month. The data file is attached – real NYC temperature data:

Average Monthly & Annual Temperatures at Central Park, from:

http://www.erh.noaa.gov/okx/climate/records/monthannualtemp.html

– note that I already put it into a tab delimited file without the header line with the month names

Use the Matrix class to hold the weather data.
Do not include the year – only the monthly averages.

Write a WeatherMenu to display numbered choices to the user of what to query from the weather data. Read and return the choice in as an int.
Examples:
1. Average temperature for a given year
2. Highest temperature for a given year
3. Average temperature for a given month
4. Highest temperature for a given month

Use command line arguments: name of file, starting year
Some reminders:
To set the command line arguments from the Visual Studio IDE: right click on the project name and select properties
Be sure the input file is in the same directory as main.cpp
Be sure the file is named correctly in the command line args

Finals time!

A long awaited spring break has finally come, but its over already!! 

Learned a lot the past few weeks in C++ and object oriented programming.  Using classes, pointers, dynamic memory whewww!  It was hard but just forcing myself to do these projects made me understand it.  Created a password checker gui using c++ and visual studios.  Getting ready for finals which will take up most of my time but i’m very excited for the summer.  Since this is when I will focus on my ruby on rails web app development!  Not sure if i’ll apply to this bootcamp I had my eye on or thinkful.  But for now I’m going to try to start the one month rails tutorial to get a head start! 

Heres a coupon if any of you guys want to try it also, http://onemonthrails.com/signup?discount_code=qFQbQF

-“Fortune favors the bold..”

I’m out!

Tagged , , ,

password program

//password.cpp implementation file
#include “password.h”

 

//copy constructor
passwordmanager::passwordmanager(const passwordmanager& otherObject)
{
string * commonPasswords = new string[passwordSize];

}

//constructor
passwordmanager::passwordmanager(string fileName)
{
cout<<“got here”;
int counter = 0, passwordSize = 0;
bool atLeastWeak = false;
bool atLeastMedium = false;
bool strongPassword = false;
bool longEnough = false;
bool containsAlphaChar = false;
bool containsNumber = false;
bool containsSymbols = false;
bool hasComPass = true;
bool isComPass = false;

ifstream infile;

infile.open(“C:\\Users\\brian\\Desktop\\passwordsUpdated.txt”);

if(!infile)
{
cout<<“Error opening file! “;
//return 1;
}
//read in contents of file to a variable inorder to get counter size
while(!infile.eof())
{
infile>>passwords;
passwordSize++;
}
infile.close();

//now I have the size of the pass word list stored in passwordSize
//made pointer called commonPasswords, dynamically allocated data for string array
commonPasswords = new string[passwordSize+10];

//Open file again
infile.open(“C:\\Users\\brian\\Desktop\\passwordsUpdated.txt”);

if(!infile)
{
cout<<“Error opening file! “;
//return 1; since im in the constructor it won’t let me return anything??
}

//read in contents of file to array
while(!infile.eof())
{
infile>>commonPasswords[counter];
counter++;
}

printRules();

sort(commonPasswords, passwordSize);

string potentialPassword;
cout<<“Please enter a password! “;
cin>>potentialPassword;

while(!atLeastWeak)
{
longEnough = checkLength(potentialPassword);
containsAlphaChar = checkForLetters(potentialPassword);
containsNumber = checkForNumbers(potentialPassword);
containsSymbols = checkForSymbols(potentialPassword);

if(longEnough && containsAlphaChar && containsNumber && containsSymbols)
atLeastWeak = true;
else
{
cout<<“Invalid password! \n”;
break;
}
if (atLeastWeak)
atLeastMedium = checkForUpperLower(potentialPassword);

if (atLeastMedium)
{
isComPass = isCommon(potentialPassword, commonPasswords, passwordSize);
hasComPass = hasCommon(potentialPassword, commonPasswords, passwordSize);

if (!isComPass && !hasComPass)
strongPassword = true;
}

printPasswordResults(atLeastWeak, atLeastMedium, strongPassword);
}
}

 

//Deconstructor
passwordmanager::~passwordmanager()
{
delete [] commonPasswords;
}

//Function checks if inputted password is at least 8 characters long
bool passwordmanager::checkLength(string potentialPassword)
{
if(potentialPassword.length()>=8)
return true;
else
{
cout<<“Password is not the required length. “;
return false;
}
}

//Function checks if there is any character from alphabet in the input password
bool passwordmanager::checkForLetters(string potentialPassword)
{
int index = potentialPassword.find_first_of(“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”,0);
if(index >= 0)
return true;
else
{
cout<<“Password does not contain a letter. \n”;
return false;
}
}

//Function checks for number in the inputted password
bool passwordmanager::checkForNumbers(string potentialPassword)
{
int index = potentialPassword.find_first_of(“0123456789”,0);
if(index>=0)
return true;
else
{
cout<<“Password does not contain a number. \n”;
return false;
}
}

//Function checks for any of the special characters (!$%?) in the inputted password
bool passwordmanager::checkForSymbols(string potentialPassword)
{
int index = potentialPassword.find_first_of(“!$%?”,0);
if(index>=0)
return true;
else
{
cout<<“Password does not contain a special character! (!%&?) \n”;
return false;
}
}

//Function checks for both an uppercase and lowercase letter in inputted password
//islower and isupper are built in functions in c++
bool passwordmanager::checkForUpperLower(string potentialPassword)
{
bool foundUppercase = false;
bool foundLowercase = false;

for(int i = 0; i<potentialPassword.length(); i++)
if(islower(potentialPassword[i]))
foundLowercase = true;
for(int i = 0; i<potentialPassword.length(); i++)
if(isupper(potentialPassword[i]))
foundUppercase = true;

if(foundUppercase && foundLowercase)
return true;
else
return false;
}

// Takes an array of passwords, its size, and the password to search
int passwordmanager::binarySearch(const string listOfPasswords[], int listLength, string searchPassword)
{
int first = 0;
int last = listLength – 1;
int mid;

bool found = false;

// check if the middle number equals searchPassword and react according
while(first <= last && !found)
{
mid = (first + last) / 2;

if (listOfPasswords[mid] == searchPassword)
found = true;
else if (listOfPasswords[mid] > searchPassword)
last = mid – 1;
else
first = mid + 1;
}

if (found)
return mid;
else
return -1;
}

//Function takes in the inputted password
bool passwordmanager::isCommon(string potentialPassword, const string commonPasswords[], int passwordSize)
{
int index;
for(int i = 0; i<potentialPassword.length(); i++)
potentialPassword[i] = tolower(potentialPassword[i]);

index = binarySearch(commonPasswords, passwordSize, potentialPassword);

//Checks if inputted password matches any on file’s list
if(index >= 0)
return true;
else if(index == -1)
return false;
else
return false;
}

//Function checks if inputted password has a password from the array that holds common passwords
bool passwordmanager::hasCommon(string potentialPassword, const string commonPasswords[], int PasswordSize)
{
string pass;
int index=0;

for(int i = 0; i<potentialPassword.length(); i++)
potentialPassword[i] = tolower(potentialPassword[i]);

for(int i = 0; i<PasswordSize; i++)
{
pass = commonPasswords[i];
if(pass.length()>2)
{
index = potentialPassword.find(pass, 0);
if(index >= 0)
return true;
}
}
return false;
}

//PrintRules function
//prints rules for getting valid passwords and rules for weak medium & strong password

void passwordmanager::printRules()
{
cout << “Password Rules\n————————————————————-\n”;
cout << “1-The password must be at least 8 characters long.\n”;
cout << “2-It must contain at least one alphabet character [A-Z][a-z].\n”;
cout << “3-It must contain at least one numeric character [0-9].\n”;
cout << “4-It must contain at least one special character from this set: ! $ % ?”;
cout << “\n\nWEAK – the minimum (passes above rules)\n”;
cout << “MEDIUM – at least WEAK and contains upper and lower case letters\n”;
cout << “STRONG – at least MEDIUM and does not contain string from the common list\n”;

}

//Function prints whether inputted password is weak medium or string
void passwordmanager::printPasswordResults(bool weak, bool medium, bool strong)
{
if (weak && !medium && !strong)
{
cout << “\nThis password is Weak.\n”;
cout << “This password is okay, you should try again! \n\n”;
}
else if (weak && medium && !strong)
{
cout << “\nThe password is a Medium strength password.\n”;
cout << “The password is acceptable I guess.\n”;
cout << “If you want a strong password you should be more creative! \n\n”;
}
else if (weak && medium && strong)
{
cout << “\nThe password is a strong password.\n”;
cout << “Awesome Password!!! \n\n”;
}
}

//sort
void passwordmanager::sort(string commonPasswords[], int passwordSize){
int indexOfNextSmallest;
for(int index = 0; index < passwordSize – 1; index++)
{
indexOfNextSmallest = indexOfSmallest(commonPasswords, index, passwordSize);
swapPasswords(commonPasswords[index], commonPasswords[indexOfNextSmallest]);
}
}

// Swaps the values of password1 and password2.
void passwordmanager::swapPasswords(string& password1, string& password2)
{
string temp;
temp = password1;
password1 = password2;
password2 = temp;
}
int passwordmanager::indexOfSmallest(const string commonPasswords[], int startIndex, int passwordSize)
{
string min = commonPasswords[startIndex];
int indexOfMin = startIndex;
for (int index = startIndex + 1; index < passwordSize; index++)
if (commonPasswords[index] < min)
{
min = commonPasswords[index];
indexOfMin = index;
//min is the smallest of a[startIndex] through a[index]
}

return indexOfMin;
}

}
//___________________________________________________________________________

 

//password.h file
#pragma once
#include<iostream>
#include<string>
#include <fstream>

using namespace std;

class passwordmanager
{
public:

bool search(string password);

bool checkLength(string potentialPassword);
bool checkForLetters(string potentialPassword);
bool checkForNumbers(string potentialPassword);
bool checkForSymbols(string potentialPassword);
bool checkForUpperLower(string potentialPassword);
bool checkForUpperLower();
bool isCommon(string potentialPassword, const string commonPasswords[], int PasswordSize);
bool hasCommon(string potentialPassword, const string commonPasswords[], int PasswordSize);
void printRules();
void printPasswordResults(bool weak, bool medium, bool strong);
void sort(string commonPasswords[], int passwordSize);
void swapPasswords(string& password1, string& password2);
int indexOfSmallest(const string commonPasswords[], int startIndex, int passSize);
int binarySearch(const string listOfPasswords[], int listLength, string searchPassword);

string potentialPassword;
passwordmanager(string fileName);
passwordmanager(const passwordmanager& otherObject);
~passwordmanager();

private:
int counter;
int passwordSize;
bool atLeastWeak;
bool atLeastMediume;
bool strongPassword;
bool longEnough;
bool containsAlphaChar;
bool containsNumber;
bool containsSymbols;
bool hasComPass;
bool isComPass;
string *commonPasswords;
string passwords;
string fileName;

};

 

//__________________________________________________________________________________
//main.cpp driver code
#include <iostream>
#include <fstream>
#include <string>
#include “password.h”
using namespace std;

int main()
{

string password = “C:\\Users\\brian\\Desktop\\passwordsUpdated.txt”;
passwordmanager object(password);

return 0;

}

 

april

Yea, I know it’s really basic level stuff, but I finally got my C++ password checker to work using classes and a dynamic array.  That’s a check in the box for me.  Feels good to get it working, still a long way to go.  

Also learning basics in hacking is really eye opening how vulnerable we are as the average computer user (surfing, emails, etc).  Your personal information and credit card numbers can be so easily taken.  But on the other hand there is a whole industry that is beginning to need good programmers to defend against attacks to our vulnerable systems, such as our electric grids, transportation, telecommunications and there is good money in it as well.  

Here’s a link to some useful information.  The DOD is really taking initiative in finding a solution to these issues.  They offer scholarships and internships.  

National Initiative For Cybersecurity Education

Other than that I can’t wait to get out of school and start working or making apps, and web sites.  A vacation from school would be nice!  

 

“you gain strength, courage, and confidence by every experience in which you stop to look fear in the face”

– E Roosevelt

keep moving!

 

Tagged , , ,