This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

invite/password script using mysql db search

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
O
OzMan
Voice
Posts: 5
Joined: Thu Jan 15, 2009 1:35 am

invite/password script using mysql db search

Post by OzMan »

Hi,

I was hoping somebody would be able to create a script for me that listens for a privmsg invite with a password (ie. /msg bot invite username password or /msg bot username password invite). It would then compare the username and password to a mysqldb to see if they match. If they both match then an invite to the channel is given to the requesting nick, if either are wrong a simple wrong user/pass msg is sent to the nick requesting the invite.

eg

/msg bot username password invite

bot checks mysqldb for matching username/password

if found it issues the invite

if no match found no invite

error msg sent.

Many thanks in advance.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

try:

Code: Select all

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

# command: /msg botnick invite <username> <password>

# invite channel
set invite_chan "#channel"

# mysql db user
set msql_user "user"

# mysql db pass
set msql_pass "pass"

# mysql server host
set msql_host "localhost"

# mysql usernames/passwords database
set msql_dbase "eggdrop_users"

# mysql usernames/passwords table
set msql_table "users"

##################################################################
bind msgm - "*" invite_privs

package require mysqltcl

proc invite_privs { nick uhost hand arg } {
	global msql_user msql_pass msql_host msql_dbase msql_table invite_chan

	set all_prv_args [split $arg]
	set priv_command [lindex $all_prv_args 0]
	set priv_username [lindex $all_prv_args 1] 
	set priv_password [lindex $all_prv_args 2]

	set login_ok 0

	if {($priv_command == "invite") && ($priv_username != "") && ($priv_password != "")} {
		set m_hand [::mysql::connect -host $msql_host -user $msql_user -password $msql_pass]
		::mysql::use $m_hand $msql_dbase

		set users_passwords [::mysql::sel $m_hand "SELECT username, password FROM $msql_table" -list]

		::mysql::close $m_hand

		foreach u_and_p $users_passwords {
			if {$u_and_p != ""} {
				set u_and_p_split [split $u_and_p]
				set user_name [lindex $u_and_p_split 0]
				set user_pass [lindex $u_and_p_split 1]

				if {$priv_username == $user_name} {
					if {$priv_password == $user_pass} {
						set login_ok 1
					}
				}
			}
		}

		if {$login_ok == 0} {
			putquick "PRIVMSG $nick :wrong username or wrong password, sorry"
		} {
			putserv "INVITE $nick $invite_chan"
		}
	}
}

putlog "mysql_invite.tcl ver 0.1 by tomekk loaded"
table for it:

Code: Select all

create table users (
        id int(4) auto_increment,
        username varchar(12),
        password varchar(12),
        primary key(id)
);
testing:
13:29:29 <tomekk> invite test qwert
13:29:29 <botty> wrong username or wrong password, sorry
13:30:29 <tomekk> invite test qwerty
13:30:32 [10] -!- botty invites you to #channel
users/passes are stored one by one, all in plain text:
user pass
user2 pass2
etc etc
mysql> select * from users;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | tomekk | 123456 |
| 2 | test | qwerty |
+----+----------+----------+
mysql> describe users;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(4) | NO | PRI | NULL | auto_increment |
| username | varchar(12) | YES | | NULL | |
| password | varchar(12) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
:>
Last edited by tomekk on Tue Jan 20, 2009 8:37 am, edited 5 times in total.
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

Impressive tomekk. :)
O
OzMan
Voice
Posts: 5
Joined: Thu Jan 15, 2009 1:35 am

LEGEND!!

Post by OzMan »

Thank you so much tomekk,

that script works GREAT!!!!!


You are a legend!!!!
Post Reply