Password

Pages: 12
I've made a password program. There's two people registered on it, another guy and me. I have the program running full screen when the computer starts up. It first asks you to enter in your username if you're allowed on the computer. If you don't type in the right one then it shuts down using this code
system("shutdown /f /s /t 60 /c Wrong Username");

system() uses the operating system. /f closes all programs without warning. /t 60 /t calls for the amount of seconds and 60 is a minute. /c is for a comment.

If you get it correct it asks for the password for that specific user. If you get the password wrong then again you have sixty seconds until the computer shuts down. It also records everything that you typed in. I have it working, but I was wondering how I could put the information in a notepad file.

So if you typed in Drue, then it would find the "Drue.txt" file in the specified location, the read the file and inside the file contains the correct password. Then if you typed in the correct password it would just exit. The reason I want it like this is so I could change the password without having to go into the code then recompile it and put it back into the startup menu. It's not hard to do that, but it takes up time depending on how often you change your password.

I want it to fine the file, read it, then compare it to the entered text.


If I need to explain anything just tell me.
Last edited on
Its really simple, you can save the variables into a text file, or a file name of your choosing, as long as you tell notepad to open it.

This tutorial will help you, thing is the file will save in the project directory as it is debugged. When compiled into an .exe it will save the file to the desktop I believe, but to customize a location for it to save you have to change the ("example.txt") part to ("c:/location/example.txt") I think...

This site has an article for it...

http://www.cplusplus.com/doc/tutorial/files/

And yes, you are going to have to recompile.

And just some side-notes, Are you serious with this program lol... Because if so people can find the text file within the 60 seconds and read the data lol... It wont be encrypted. :|
And cant they just ignore the application? or close it?
Last edited on
Thanks. I already know how to save it to a specific location. BTW when you have the C:/ you have to use another slash. But thanks.

How would I compare it to what the user typed in?
Last edited on
An If statement would do it.

Post your code here Ill help you out... I can make an encryption for you, and do the appropriate if statements and whatnot... I made something similar two months ago.
Last edited on
BTW when you have the C:/ you have to use another slash


There is a different between:
"C:/Program Files/etc" <--This is OK
"C:\\Program Files\\etc" <-- This is also OK
"C:\Program Files\etc" <-- This is not ok
I currently don't have it with me. I do sound at our church and I made it on the sound computer, but i can make a sample one. A program real quick that is similar. But I really did make one.
Last edited on
@DoTTGaMMA How can they access the file if they can't log into the computer?

Which leads be to another question, what OS are you using? If it is windows, why don't you have add account login. If you have Linux, at which point in the boot sequence does it run?

You could also do something really cool and have the program email you and your friend whenever someone tries to login incorrectly onto the machine. Then you know at any time when someone tries to log into that machine when they shouldn't be. ;)
Last edited on
The main reason was so we could monitor who tries to log on. And I wanted to do this the hard way and not just make a login password. And this way if we tell someone how to get on for one time we can go back and change the password without me having to go into the source code though it is really simple, but here's the code.




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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <iostream>


using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{

    MainScreen:
cout << ("Loading...");
    system("setlocal delayedexpansion");/// wait time
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");
    system("setlocal delayedexpansion");



    /////////////////////////////////////////////////////////////////////////////
system("title Password"); //sets cmd title
     string Username;
    cout << "Enter in your username                -";
    cin  >> Username;
    ofstream Log;
    Log.open("C:\\Program Files\Password Log\Log.txt", ios::app);
    Log << "Username = " << Username << "\n";

    if(Username == "Drue" || Username == "drue")
    {
        system("cls");



        string DruePassword;
        cout << "Type in your password               -";
        cin >> DruePassword;
        Log << "Password = " << DruePassword << "\n\n";
        if(DruePassword == "Blake" || DruePassword == "blake")
        {
            system("cls");
            cout << "Thank you";
            return 1;
        }
        else
        {
            system("shutdown /f /s /t 60");
        }
    }



else{

system("cls");
cout << "Wrong Password";

    system("shutdown /f /s /t 60");
}




}



I'm making it for an XP.
Last edited on
I'm not sure of a code to make it open maximized, though if you have one it would be nice, so I just changed the properties when I ran it to open full screen.
I'm using a string because it is easy to use if statements with it, but cin.getline(); won't work. So do you know how I could do that?

I also batch or at least, that's why I do some of the stuff shows.

system("cls"); clears the screen. And system("pause>nul"); pauses the program to wait without adding the "Press Enter to continue" thing up.
Last edited on
Its not very secure. What is stopping someone from just exiting the program without entering anything into it?

Again I ask, why don't you setup accounts on the windows system?
Last edited on
I set it so it opens fullscreen. They can't press the red 'x' and i don't know how to make it so it can't be closes using taskkill , task manager, or getting around it using
Alt + Tab.
It won't let me view full screen on Windows Vista, but on the Xp it's for it lets me. I did it this way because I was bored and I wanted know if people tried to login.
Last edited on
I don't think you should worry about it. I mean no offense, but isn't it just a toy program? It even wastes time while pretending to "load". If you really want to control those things you'll need to drop the system calls and use the Windows API. But if it were me, I'd focus on interesting/useful things.
Well, why don't you change the program that it runs at start up and records the time when someone logged in and appends that information to a file. Or it can email you the login time. I don't see a way otherwise to make it secure besides adding windows account login.
Windows API? And I don't know hwo to make it record the time someone was logged in, or how to make it email you something.

I'm also only 14, and this is helping me to learn C++.

Last edited on
Well you wouldn't have to use the windows API. Just use ctime, create a timestamp when the program runs and append that information to a file. The email functionality is something that might be out of your capabilities at the moment but if you are interested in learning how to do it you can google it. I found this post which has some useful information in it:

http://www.codeguru.com/forum/showthread.php?t=300530
Last edited on
Thank you. I'm in the process of creating a program (the designs are already made), but I need to write the entry to a file. The only problem is that it is a Windows App. The link for what I've meade is underneath this.

https://rapidshare.com/files/459825879/GraceAG.exe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using namespace System;

int main( ) 
{
   Int32 tc = Environment::TickCount;
   Int32 seconds = tc / 1000;
   Int32 minutes = seconds / 60;
   float hours = static_cast<float>(minutes) / 60;
   float days = hours / 24;

   Console::WriteLine("Milliseconds since startup: {0}", tc);
   Console::WriteLine("Seconds since startup: {0}", seconds);
   Console::WriteLine("Minutes since startup: {0}", minutes);
   Console::WriteLine("Hours since startup: {0}", hours);
   Console::WriteLine("Days since startup: {0}", days);

   return 0;
}


I just found this code on Microsoft.com

It's for the elapsed time.
Last edited on
I've come across a few errors while copying your code to add stuff to...

While I'm fixing the errors(prob from compiler change) you should take a look at this site
http://www.adrianxw.dk/SoftwareSite/index.html

I learned a LOT from it... and the tutorials are in normal people talk. No jargon, since it seems like you want to learn c++ more.

I will post your code here later, with some "bells and whistles" added that I will explain in notes.


btw are you still trying to use system api... Because I saw the windows api link from rapidshare and WOW. that looks great! You should just work on that.
Last edited on
Thanks. I was using CodeBlocks compiler and it worked fine. Thanks by the way. I think I've found a way to write to file with the Windows Application. What I want in the link I sent is that when you click a button (on a page that you input information) it saves it all to a .rtf file.
Pages: 12