
-----------------------------------
Balmung
Wed May 16, 2007 8:26 am

User Creation Crash.
-----------------------------------
I am having a problem creating a user, when it asks for the user if it already exsists and they try to make that user again it crashes >_< can i get some help?


procedure create
    var name : string
    var password : string
    var sn1 : int
    var sure : string

    put "Enter Username: " ..
    get name
    put "Enter Password: " ..
    get password
    if File.Exists ("users/" + name + ".ini") then %% cheaks if user exsists
        put "User Exsists"
        loop  %% If user Exsists Ask for a New User
            put "Enter Username: " ..
            get name
            put "Enter Password: " ..
            get password
            put "Are you sure? " ..
            get sure
            loop
                if sure = "Yes" or sure = "yes" then %% If yes then create
                    if File.Exists ("users/" + name + ".ini") then %% cheaks if user exsists
                        put "User Exsists"
                        exit
                    elsif File.Exists ("users/" + name + ".ini") = false then
                        open : sn1, "users/" + name + ".ini", put
                        put : sn1, name, " ", password
                        put "User Created"
                        exit
                    elsif sure = "No" or sure = "no" then %% If No Go Back
                        cls
                        exit
                    end if
                end if
            end loop
            if File.Exists ("users/" + name + ".ini") then
                exit
            end if
        end loop
    else
        open : sn1, "users/" + name + ".ini", put     %%Creates User Name
        put : sn1, name, " ", password
        put "User Created"
        delay (1000)
    end if
    close : sn1
end create


-----------------------------------
d2bb
Wed May 16, 2007 11:03 am

RE:User Creation Crash.
-----------------------------------
try using a boolen.


so if user1 = true

Code: 


User1 =true
if user1=true then
put " enter another name"
else user1=false then
put "Your user has been made"
end if.



just a thought. may or may not work with ur code.

-----------------------------------
DIIST
Wed May 16, 2007 5:10 pm

Re: User Creation Crash.
-----------------------------------
All that could have been simplified too:
/**
 n-name
 p-pasword
 retruns true if succesfull, false if failed
 */
function createUser (n, p : string) : boolean
    if File.Exists ("users/" + n + ".ini") then
        result false
    end if
    var stream : int
    open : stream, "users/" + n + ".ini", put
    put : stream, n, " ", p
    result true
end createUser

/**
 Main Program
 ***/

var name, password : string := ""
loop
    put "Enter Username: " ..
    get name
    put "Enter Password: " ..
    get password

    exit when createUser (name, password)
    put "All ready exists, please enter another one"
end loop


As for the error i think it was just that when you close the snl it should be inside the if where it is open not outside. Hope this helps 
 :wink:

lilmizeminem you shouldn't be spamming :naughty:

-----------------------------------
Balmung
Thu May 17, 2007 7:49 am

RE:User Creation Crash.
-----------------------------------
Thanks ^^
