0

I am writing a program that will calculate password strength according to two formulas. One of these formulas requires me to extract certain parts of the password, first character, next seven, next 12, and all remaining characters. I am having trouble extracting all the remaining characters.

I am unsure how what to put in the upper bounds for the substring method. Here is my code.

Any help would be greatly appreciated!

cout << "Now please enter a password of 20 characters or more (including spaces!):" << endl; getline(cin, twenty_password); cout << "What character set is being used?"; cin >> character_set_20; twenty_length = twenty_password.length(); twenty_ent_strength = (twenty_length*((log(character_set_20)) / (log(2)))); first_char_twenty = twenty_password.substr(0, 1); next_seven_twenty = twenty_password.substr(1, 7); next_twelve = twenty_password.substr(7, 19); 

3 Answers 3

4

Just leave the upper bound out

http://en.cppreference.com/w/cpp/string/basic_string/substr

basic_string substr( size_type pos = 0, size_type count = npos ) const; 

You'll see that the default value is npos, meaning the remainder of the string.

(Hold on to that website! It answers your questions much faster than we do)

Sign up to request clarification or add additional context in comments.

Comments

0
lastbit = password.substring(25); 

will return substring from 25 up till end of string

Comments

0
first_char_twenty.clear(); next_seven_twenty.clear(); next_twelve.clear(); remaining.clear(); if ( twenty_password.size() >= 1 ) { first_char_twenty = twenty_password.substr(0, 1); } if ( twenty_password.size() >= 2 ) { next_seven_twenty = twenty_password.substr(1, 7); } if ( twenty_password.size() >= 9 ) { next_twelve = twenty_password.substr( 8, 12); } if ( twenty_password.size() >= 21 ) { remaining = twenty_password.substr( 20 ); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.