473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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

4 1694
Banfa
9,065 Expert Mod 8TB
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
trouty
4
indeed that is what I am trying to do, to issue a new passwordback to the employee
Sep 23 '10 #3
trouty
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
trouty
4
Thank you so very much , maybe I'll get a raise if this works. Once again thanks.
Sep 24 '10 #5

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

Similar topics

1
by: Ren? M?hle | last post by:
I have a psp script with a procedure just to run an update on one table. The Problem occurs when I try to compile this script with pspload: ORA-20006: "frsys_updatereport.psp": compilation...
1
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer...
2
by: jt | last post by:
Looking for an example how to convert and CString to an ASCII character string. Any examples on how to do this? Thank you, jt
0
by: MLH | last post by:
Is an apostrophe a character of special significance to MySQL in a way that would cause "Bob's dog" to become translated into a 12-character string when typed into a MySQL memo field? If I type...
7
by: Justin | last post by:
i need to build the unsigned character string: "PR0N\0Spam\0G1RLS\0Other\0Items\0\0\0" from the signed character string: "PR0N Spam G1RLS Other Items" Tokeninzing the character string is not...
5
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** ...
25
by: lovecreatesbeauty | last post by:
Hello experts, I write a function named palindrome to determine if a character string is palindromic, and test it with some example strings. Is it suitable to add it to a company/project library...
8
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
1
by: brettg | last post by:
With Windows Vista, we can no longer write application settings to the HKEY_LOCAL_MACHINE Registry key in the same way. If we don't have Admin permission, our entry will be "virtualized" to our own...
0
by: j2aaaa | last post by:
I have my Serial Port configuration all setup however how do i send a 26 character string over to the hardware device, with the 25 and 26 position being CR and LF? I had started teh command but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.