By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

How to write an application that generates a password from a five character string

P: 4
My company wants me to write an application that generates a password from a five character string that the user enters. This is for security reasons for employees that have to enter the building on the weekends. I remember bits and pieces from school days but can't remember the actual coding, I think you have to reverse the order of the string and subtract 15 from the ASCII code?
Sep 23 '10 #1

✓ answered by trouty

I think this is it, but can someone confirm that I am not missing anything


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  #include <string> 
  3.  
  4. using namespace std; 
  5.  
  6. int main()
  7. {
  8. //define variables
  9.     string plaintext;//store user input
  10.     char password;//store password character    
  11.  
  12. //prompt for string
  13. cout<< "\nEnter a five character name";
  14. cin>> plaintext;
  15.    if(plaintext.size()!=5)
  16.    {    
  17.      //display error message if name is not entered
  18.      cout<<"error:you must enter name!";
  19.    }
  20.    else
  21.    {
  22.        cout<<"pw is";
  23.        password=plaintext.at(4)-15;
  24.        cout<<password;
  25.        password=plaintext.at(3)-15;
  26.        cout<<password;
  27.        password=plaintext.at(2)-15;
  28.        cout<<password;
  29.        password=plaintext.at(1)-15;
  30.        cout<<password;
  31.        password=plaintext.at(0)-15;
  32.        cout<<password;
  33.    }
  34.  
  35.  
  36.  
  37.    return 0; // indicate that program ended successfully
  38.  
  39. } // end function main

Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
Do you mean to store for later recognition when the user enters the string again or are you going to supply the password back to the user for them to use?
Sep 23 '10 #2

P: 4
indeed that is what I am trying to do, to issue a new passwordback to the employee
Sep 23 '10 #3

P: 4
I think this is it, but can someone confirm that I am not missing anything


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  #include <string> 
  3.  
  4. using namespace std; 
  5.  
  6. int main()
  7. {
  8. //define variables
  9.     string plaintext;//store user input
  10.     char password;//store password character    
  11.  
  12. //prompt for string
  13. cout<< "\nEnter a five character name";
  14. cin>> plaintext;
  15.    if(plaintext.size()!=5)
  16.    {    
  17.      //display error message if name is not entered
  18.      cout<<"error:you must enter name!";
  19.    }
  20.    else
  21.    {
  22.        cout<<"pw is";
  23.        password=plaintext.at(4)-15;
  24.        cout<<password;
  25.        password=plaintext.at(3)-15;
  26.        cout<<password;
  27.        password=plaintext.at(2)-15;
  28.        cout<<password;
  29.        password=plaintext.at(1)-15;
  30.        cout<<password;
  31.        password=plaintext.at(0)-15;
  32.        cout<<password;
  33.    }
  34.  
  35.  
  36.  
  37.    return 0; // indicate that program ended successfully
  38.  
  39. } // end function main
Sep 23 '10 #4

P: 4
Thank you so very much , maybe I'll get a raise if this works. Once again thanks.
Sep 24 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.