예제 #1
0
파일: work.cpp 프로젝트: MrDjoy/TinyQQ
void work::loginmsg(int st, int o_userid, const char *passwd) //处理login消息
{
	struct msg_t msg;
	memset(&msg, 0, sizeof(msg));
	msg.head[0] = 2; //系统消息
	msg.head[2] = 0; //暂时保留,填0
	msg.head[3] = 0; //暂时保留,填0

	if ((o_userid < 0) || (o_userid >= CLIENTCOUNT)) //无效的userid
	{
		printf("login failed, %d:invalid userid\n", o_userid);
		msg.head[1] = 1; //无效userid
		send(st, (const char *) &msg, sizeof(msg.head), 0);
		close(st);
		return;
	}
	if (!auth_passwd(o_userid, passwd))//验证用户登录UserId和密码
	{
		printf("login failed, userid=%d,passwd=%s:invalid password\n", o_userid,
				passwd);
		msg.head[1] = 2; //无效密码
		//给client端socket下发系统消息
		send(st, (const char *) &msg, sizeof(msg.head), 0);
		close(st);//验证失败,关闭client socket,函数返回
		return;
	}

	printf("%d:login success\n", o_userid);
	fix_socket_client(o_userid, st); //将登录密码验证通过的客户端client安装到socket_client[]的数组中
	broadcast_user_status(); //向socket_client数组中所有socket广播用户状态消息
}
예제 #2
0
void work::loginmsg(int st,int o_userid,const char* passwd)
{
	struct msg_t msg;
	memset(&msg,0,sizeof(msg));
	msg.head[0] = 2;
	msg.head[2] = 0;
	msg.head[3] = 0;
	
	if( (o_userid < 0) || (o_userid >= CLIENTCOUNT) )
	{
	     printf("login failed, %d:invaild userid\n",o_userid);
	     msg.head[1] = 1;
	     send(st,(const char*)&msg,sizeof(msg.head),0);
	     close(st);
	     return ;
	} 	
	if(!auth_passwd(o_userid,passwd))
	{
	   printf("login failed ,userid = %d ,passwd = %s :invailed password\n",o_userid,passwd);
	   msg.head[1] = 2;
	   send(st,(const char*)&msg,sizeof(msg.head),0);
	  close(st);
	 return ;
	   
	}
	printf("%d: login success\n",o_userid);
	fix_socket_client(o_userid,st);
	broadcast_user_status();	
}
예제 #3
0
파일: authtest.c 프로젝트: MhdAlyan/courier
int main(int argc, char **argv)
{
int	argn;
const char *service="login";

	for (argn=1; argn<argc; argn++)
	{
	const char *argp;

		if (argv[argn][0] != '-')	break;
		if (argv[argn][1] == 0)
		{
			++argn;
			break;
		}

		argp=argv[argn]+2;

		switch (argv[argn][1])	{
		case 's':
			if (!*argp && argn+1 < argc)
				argp=argv[++argn];
			service=argp;
			break;
		default:
			usage();
		}
	}
	if (argc - argn <= 0)
		usage();

	courier_authdebug_login_level = 2;

	if (argc - argn >= 3)
	{
		if (auth_passwd(service, argv[argn],
				argv[argn+1],
				argv[argn+2]))
		{
			perror("Authentication FAILED");
			exit(1);
		}
		else
		{
			fprintf(stderr, "Password change succeeded.\n");
			exit(0);
		}
	}
	if (argc - argn >= 2)
	{
		if (auth_login(service, argv[argn],
			       argv[argn+1],
			       callback_pre,
			       NULL))
		{
			perror("Authentication FAILED");
			exit(1);
		}
	}
	else if (argc - argn >= 1)
	{
		if (auth_getuserinfo(service, argv[argn],
				     callback_pre,
				     NULL))
		{
			perror("Authentication FAILED");
			exit(1);
		}
	}
	exit(0);
}