Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A password system
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
iker




PostPosted: Thu Nov 03, 2005 10:12 pm   Post subject: A password system

Here is a source code for a system to start a program with a password. It outputs the password along with all the other data to a .dat file.

code:

var saver, pw : string (1)
var savestate, pw1, pw2 : string (10)
var f, ex1, ex2 : int := 0
var b : int := 2

procedure project
    loop
        locate (1, 1)
        put "this is where you put your project"
        locate (2, 1)
        put "ex1=", ex1
        locate (3, 1)
        put "ex2=", ex2
        locate (4, 1)
        put "write a new value for ex1"
        locate (5, 1)
        get ex1
        locate (6, 1)
        put "write a new value for ex2"
        locate (7, 1)
        get ex2
        locate (8, 1)
        put "save new values? [y][n]"
        locate (9, 1)
        get saver
        if saver = 'y' then
            open : f, savestate + '.dat', put
            put : f, pw2
            put : f, ex1
            put : f, ex2
            close : f
        end if
        locate (10, 1)
        put "exit and start again? [y][n]"
        locate (11, 1)
        get saver
        if saver = 'y' then
            pw2 := ' '
            ex1 := 0
            ex2 := 0
            cls
            exit
        end if
        cls
    end loop
end project

loop
    loop
        loop
            locate (1, 1)
            put "[N]ew" ..
            locate (2, 1)
            put "[L]oad" ..
            locate (3, 1)
            getch (saver)
            cls
            exit when saver = 'l'
            exit when saver = 'n'
        end loop
        locate (1, 1)
        put "username" ..
        locate (2, 1)
        get savestate
        cls
        locate (1, 1)
        put "password" ..
        pw1 := ' '
        pw2 := ' '
        loop
            locate (2, b)
            getch (pw)
            exit when pw = (KEY_ENTER)
            if b < 10 then
                put '*' ..
                pw1 := pw1 + pw
                b += 1
            end if
        end loop
        b := 2
        if saver = 'n' then
            loop
                locate (2, b)
                getch (pw)
                exit when pw = (KEY_ENTER)
                if b < 10 then
                    put '*' ..
                    pw2 := pw2 + pw
                    b += 1
                end if
            end loop
            b := 2
            if pw1 = pw2 then
                if File.Exists (savestate + '.dat') then
                    locate (1, 1)
                    put "Name already in use" ..
                    getch (saver)
                    cls
                else
                    locate (1, 1)
                    put "Signing in..." ..
                    delay (1000)
                    open : f, savestate + '.dat', put
                    put : f, pw2
                    put : f, ex1
                    put : f, ex2
                    close : f
                    exit
                end if
            else
                locate (1, 1)
                put "Passwords do not match" ..
                getch (saver)
                cls
            end if
        elsif saver = 'l' then
            open : f, savestate + '.dat', get
            if Error.Last = eNoError then
                get : f, pw2
                pw2 := ' ' + pw2
                if pw2 = pw1 then
                    get : f, ex1
                    get : f, ex2
                    close : f
                    locate (1, 1)
                    put "Signing in..." ..
                    delay (1000)
                    cls
                    exit
                end if
            else
                locate (1, 1)
                put "Invalid name or password" ..
                getch (saver)
                cls
            end if
        end if
    end loop
    game
end loop


the only current problem is that you cannot backspace the password, but can easily be fixed, and I'm just too lazy to do so
Sponsor
Sponsor
Sponsor
sponsor
iker




PostPosted: Tue Nov 08, 2005 4:59 pm   Post subject: (No subject)

any comments? maby?
MysticVegeta




PostPosted: Tue Nov 08, 2005 7:22 pm   Post subject: (No subject)

Error on running it
Error after entering the username after deleting the game procedure.
jamonathin




PostPosted: Wed Nov 09, 2005 6:54 am   Post subject: (No subject)

Works fine after you comment out "game" (second last line; im guessing thats when you will be playing your game with your registered user). Run the program yourself, you'll see that the words start to overwrite the previous words, but not fully. For example, tell the user that they're re-entering the password (dont just say password again), and clear off the ***'s in the way, and once you make an account, you need to cls first.

good job tho.
iker




PostPosted: Wed Nov 09, 2005 7:55 pm   Post subject: (No subject)

yah, i realized that too, but its just a basic way of using a password to enter a program. Btw, there shouldnt of been any errors...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: