check.c

来自「ipt网关源码」· C语言 代码 · 共 67 行

C
67
字号
#include <stdio.h>
#include <string.h>
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>

#include "database.h"

void trim(char*);

//功能:验证用户身份
//输入:用户名和密码字符串
//输出:成功返回1;失败返回-1;//用户名不存在返回0(还没用)

int check(char* username,char* password)
{
	int length; //字符串长度
	
	
    DBCHAR passwd[10];
	
	
	
    //消除“#”
	length=strlen(username);
	username[length-1]=0;

    length=strlen(password);
	password[length-1]=0;
	
	printf("Username is %s \nPassword is %s \n",username,password);

    //查询数据库的用户信息表(user_info)来确定用户帐户和密码是否匹配!!
	  
		 dbfcmd(dbproc," SELECT a002 FROM user_info WHERE a001 LIKE '%s'",username);
        
		/* Send the command to SQL server and start execution*/
		dbsqlexec(dbproc);

		/* Process the command */
		while(return_code=dbresults(dbproc)!=NO_MORE_RESULTS)
		{
			if(return_code==SUCCEED)
			{
				/* Bind results to program varibles */
				dbbind(dbproc, 1,STRINGBIND,(DBINT)0, passwd);
			
				while(dbnextrow(dbproc)!=NO_MORE_ROWS)
				{  //用户验证处理过程
					//消除字符串中的空格
					trim(passwd);
				  if (!strcmp(password,passwd))
	                 return(1);
	              else
	               //用户验证失败返回-1 
	                 return(-1);

				}
               return(0);

			}

		}


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?