Complete User and Pass Creation





5
Date Submitted Sat. Oct. 28th, 2006 8:07 AM
Revision 1 of 1
Beginner FlyingIsFun1217
Tags C
Comments 2 comments
Simple C++ program that creates a directory with the asked username, and places 2 files within the directory that contain the asked for username and the asked for password.

This is an edit of another snippet I made, but I have fixed the creation of the user's folder so it is named after the user.

FlyingIsFun1217

#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>

using namespace std;

int main()
{

    std::string newusername;
    std::string newuserpassword;
   
    {
    cout<<"Please enter a user name to use (one word only, 30 letters): ";
    cin>>newusername;
    cin.ignore();
   
    cout<<"\n"<<newusername<<" is now being used as your username.\n\n";
    cout<<"Enter a password to use for "<<newusername<<"'s account: ";
    cin>>newuserpassword;
    cin.ignore();
   

    cout<<"\nPlease wait while your account ('"<<newusername<<"') is created...";
    cout<<"\n\nCreating User Folder...";
   
    mkdir("C:/Program Files/MUMS/");
    std::string newDir="C:/Program Files/MUMS/"+newusername;
    mkdir(newDir.c_str());
   
    cout<<"\nCreating Username File...";
   
    std::string unfile="C:/Program Files/MUMS/";
    unfile+=newusername;
    unfile+="/username.mums";
   
    ofstream usernamecreate;
    usernamecreate.open(unfile.c_str());
    usernamecreate<<newusername<<endl;
    usernamecreate.close();
       
    cout<<"\n"<<newusername<<"'s User Name file successfully created!...";
   
    cout<<"\nCreating Password File...";


    std::string pfile="C:/Program Files/MUMS/";
    pfile+=newusername;
    pfile+="/password.mums";
   
    ofstream userpasswordcreate;
    userpasswordcreate.open(pfile.c_str());
    userpasswordcreate<<newuserpassword<<endl;
    userpasswordcreate.close();
   
    cout<<"\n"<<newusername<<"'s Password saved successfully!...";
   
    cout<<"\n\nDone!";
    cout<<"\n\nYour User Name is '"<<newusername<<"' and your password is '"<<newuserpassword<<"'.\n"
          "Make sure that you know these, as there is no way of retirieving\nthis information.";
    cin.get();
    }
}
 

Comments

Comments Should be CPlusPlus
Thu. Nov. 2nd, 2006 12:53 PM    Scripter sehrgut
Comments C++ it is :)
Sat. Nov. 11th, 2006 12:09 AM    Beginner FlyingIsFun1217

Voting