Solved

Data files...

Posted on 1998-12-11
6
201 Views
Last Modified: 2010-04-02
I have an application that has three passwords. In this application I can change all of them if I want to. The three passwords are stored in an ordinary text file. When the program begins, the passwords are read from the file. When the program closes, the new passwords are saved to the file.

My question is this,

1. How do I read the passwords from the file?
I did use this code but it has problems when the password is set to nothing, ie no password
            char password1 [10];
            fscanf( pf, "%[^\n]\n", password1 );
            char password2[10];
            fscanf( pf, "%[^\n]\n", password2);
              char password3[10];
            fscanf( pf, "%[^\n]\n", password3);
I thought the scan would read until a new line so each password was on a new line.

2. Obviously if someone just opens the text file, then they have the passwords. How do I write to the file and change the characters that are written?

Thank you
0
Comment
Question by:rose337
6 Comments
 

Author Comment

by:rose337
ID: 1179922
By the way, the reason for the parameters in fscanf is that the passwords may be more than one word seperated by spaces. So my idea was that each password would be on seperate line in the text file and the scan would read to the end of the line (\n). This worked great until I change the password to nothing so the text file had an empty line and crash!
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1179923
There is an encryptor that you can use.  But I will if you don't want anything to technical then I suppose I will give this as an answer...
0
 
LVL 1

Accepted Solution

by:
The_Brain earned 70 total points
ID: 1179924
There are two things that you can do anyway, just to optimise.

char password[3][10]={{'\0}}

/*init of array. this is saying 3 passwords with a length of 10 characters... password[0], password[1] and password[2] there are the three password, each has length potential of 10 char.*/

for (int count=0; count<3; count++)
 {
   fscanf( pf, "%[^\n]\n", password[count]);

/*this is done three times so that the password[0]----> to password[2] can be accessed, in factnow with minimal fuss you can add any amount of passwords by just increasing the array password[x][10]*/
 
 }
the scanf is a great thing to use, I haven't had to much to do with it.  but the empty line problem is obvious, but I can't solve that.  don't make no password.  make a default password

but now, to encrypt not too complicated, just so that you get the idea. //without the original comments.
I wouldn't use, scanf for such a small thing.
I would do this...

char password[3][10]={{'\0}}
char inputfile[]="password.txt"

ifstream input(InputFile);

if (!input)
  cout<<"ERROR in file name.";
else
{
   for (int count=0; count<3; count++)
     {
        input.getline(password[count],10); /*puts the line in password[count] */
     /* for the encrypt;
     for (int i=0; i<10; i++)
        {
           password[count][i]+=12;        /*shifts all the letter by 12 positions.*/
         }
     cout<<password[count]
 }
//This is only encrypt reading, I have n't actually put this encrypted form into the file, as you can see, I only read and encrypted,
I don't wanna do it for you so do whatever you  do to get and put things into the file, and use a similar kind of algo, USE 3d arrays for this kind of thing.  that is what makes it easier If you really want me to I will do this for you,  you will have to e-mail me for it.  g_dutoit@hotmail.com

good luck

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 1179925
A shift substitution cypher like that (where a value is added to each digit) is extremely easy to crack.  It ca ussually be cracked on the first try, but if not a few attempts will do it.  (256 attempts are guaranteed to do it.)

A rolling XOR would be better for this,  Again it is not high security, but since the data length is short it is hard to crack the XOR.  In fact,if you make XOR pattern 30 or more in length, it will never repeat which makes this harder to crack.  However, if the user has the ability to change their own passwords, then they can learn the XOR pattern (or the shift in the shift cypher above),  and can crack others passwords easily (1st attempt).
0
 
LVL 1

Expert Comment

by:andla
ID: 1179926
The_Brain>> char password[3][10]={{'\0}} ??


//Not sure?
password[count][i]+=12;
Is the 11 character the \0? and the 12 character the adress of the next X in [X][10]?

Your sincerely
Andla
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1179927
nonono.

password[3][10] three passwords with 10 characters each.
10th char is '\0'

"012345678\0" is the limit.  Well sorry to answer the query soo late. I just never saw the answer.  (THE BLOODY EE won't e-mail me to tell me which Questions are changed!)

:^) well happy new year!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now