A quick, simple, beginner friendly snippet for ini based user registration/login management. I will expand this code when I have some spare time.
Usages:
Place code in remotes section of your script editor.
Register: register password Login:
login password
Checking if a user is logged in example: if ($readini($+($1,.ini),info,loggedin) == true) { /notice $nick You Are Already Logged In | halt }
; Ini based registration/login system v0.1 by ares
; /register username password
alias register {
writeini $($1,.ini) info password $2
writeini $($1,.ini) info loggedin false
}
; /login username password
alias login {
if ($readini($+($1,.ini),info,password) == $2) {
writeini $($1,.ini) info loggedin true
notice $1 You Have Successfully Logged In.
}
}
on *:Text:`login*:?: {
if (!$2) { /notice $nick Usage: `login password | halt }
if ($readini($+($1,.ini),info,password) == $null) { notice $nick You have not registered. | halt }
if ($readini($+($1,.ini),info,password) == false) { notice $nick You have not set a password. | halt }
if ($readini($+($1,.ini),info,loggedin) == true) { notice $nick You Are Already Logged In | halt }
login $nick $2
}
on *:Text:`register*:?: {
if (!$2) { notice $nick Usage: `register password | halt }
if ($readini($+($1,.ini),info,password) = !$null) { notice $nick Your already registered | halt }
if ($2 = !$isalnum) { notice $nick Special characters are not supported. Characters Supported: a-z and 0 - 9 | halt }
register $nick $2
notice $nick You are now registered with the password: $2
}
The reason I'm using a new ini file for each nick is for user administration purposes. It's a matter of personal preference, There's no difference using separate ini files, and its not hard to make the script store the user files in a separate directory for tidiness.
Thanks for comments, snippet updated
http://www.hawkee.com/snippet/8261/
It's alright, but you should advance it more so you can use commands such as
on 2:text:user command:#: {
and
on 3:text:admin command:#: {
This can be done with using guser and luser I believe.
Hmm, and it looks like you are writing a new ini for each user?
I would just do
writeini users.ini $nick $2
and
$readini(users.ini, $nick, password)
etc...