cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Windows Programming : A password maker...
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

question  A password maker...

Dillyto666 (8)
Hi, Its Dilyan again. Now I want to make a simple console program wich makes
complex passwords. I have an Idea how It will work, but don't know how to write it down.
The user first must input his name or a word and then the PC must put a random number after the first 3 letters (from 0 to 49), then he must take the last 2 letters and then replace them with a random letter (from B to W). After that he must replace the middle 1 letter with a random number (23 to 78).
After that he must type the created character string on the screen.

This is how the program must act.

Thanks for reading.
|
Duoas (1458)
Use a std::string. It has useful stuff for doing stuff like inserting and replacing letters.
http://www.cplusplus.com/reference/string/string/

Use the rand() functions in <cstdlib> to get random numbers and std::stringstream to convert them to a number.
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
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

string get_random_number_string( int min, int max )
  {
  int num;
  num = (rand() %(max -min +1)) +min;
  ostringstream result;
  result << num;
  return result.str();
  }

int main()
  {
  // initialize the random number generator
  srand( time( NULL ) );

  cout << "A random number in 0..49: "  << get_random_number_string(  0, 49 ) << endl;
  cout << "A random number in 23..78: " << get_random_number_string( 23, 78 ) << endl;

  return 0;
  }


Have fun!
|
Dillyto666 (8)
Thats realy nice Duoas! Your program works, and I looked at the STRING tutorials you gave me the link for, I sellected the Insert operator, but I didn't saw a command which puts random nums or letters in the half of the inputted from the user string. But any way you helped me alot.
Thanks.
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us