Пример #1
0
int main(void)
{
     mysqlpp::Connection c(false);
     if (!c.connect("okzoniom", "localhost", "okzoniom", getDBIdent().c_str())) {
          cgi_redirect("./error.okz?state=err_db");
          return 0;
     } else {
          //Set UTF8
          mysqlpp::Query q = c.query("SET NAMES utf8");
          q.exec();
     }

     cgi_init();
     cgi_session_save_path("sessions/");
     cgi_session_start();

     cgi_process_form();

     std::string login = getParam("login");
     std::string mdp = getParam("password");


     if (login.empty() || mdp.empty()) {
          cgi_redirect("./login.okz?state=err_fill_all_field");
          return 0;
     }

     //Login regex
     boost::regex reg_pseudo("[a-zA-Z0-9]{2,}");
     if (!regex_match(login, reg_pseudo)) {
          cgi_redirect("./login.okz?state=err_login_char");
          return 0;
     }

     std::string password;

     mysqlpp::Query query = c.query("SELECT password FROM game_account where login=%0Q;");
     query.parse();
     mysqlpp::StoreQueryResult r = query.store(login);
     if (r && r.num_rows() > 0) {
          r[0]["password"].to_string(password);
     } else {
          cgi_redirect("./login.okz?state=err_no_account");
          return 0;
     }

     hashwrapper* wrapper = new md5wrapper();
     std::string md5mdp = wrapper->getHashFromString(mdp);
     delete wrapper;
     if (password == md5mdp) {
          cgi_session_register_var("login", login.c_str());
          cgi_session_register_var("locale", "fr_FR.UTF-8");
     } else {
          cgi_redirect("./login.okz?state=err_password");
          return 0;
     }

     cgi_redirect("./index.okz");
     return 0;
}
Пример #2
0
SCM scgi_session_register_var (const SCM name, const SCM value)
{
  /* todo: remove gh_scm2newstr when Guile 1.8 is released */
  char *n;
  char *v = gh_scm2newstr (value, NULL);
  int retval;

  if (SCM_SYMBOLP(name))
    {
      n = gh_symbol2newstr (name, NULL);
    }
  else
    {
      n = gh_scm2newstr (name, NULL);
    }

  retval = cgi_session_register_var (n, v);

  free (n);
  free (v);

  if (retval)
    {
      return SCM_BOOL_T;
    }
  else
    {
      return SCM_BOOL_F;
    }
}
Пример #3
0
int main(int argc, char *argv[])
{
	cgi_init();
	cgi_session_start();
	cgi_process_form();
	cgi_init_headers();

	sqlite3 *db;
	char *err = 0;
	char *sql = NULL;
	char **result=NULL;
	int row=0,col=0;
	int ret = 0;
	ret = sqlite3_open(DATEBASE,&db);
	if(ret != SQLITE_OK)
	{
		fputs(sqlite3_errmsg(db),stderr);
		fputs("\n",stderr);
		exit(1);
	}
	sql = sqlite3_mprintf("select U_prim from UserInfo where U_id='%s' and U_pwd='%s'",
						  cgi_param("user"),cgi_param("password"));
	ret = sqlite3_get_table(db,sql,&result,&row,&col,&err);
	if(ret != SQLITE_OK)
	{
		fputs(err,stderr);
		fputs("\n",stderr);
		sqlite3_close(db);
		exit(1);
	}
	if(col == 0 && row == 0)
	{
		/* 修改路径 */
		printf("bad input");
		printf("%s  ",cgi_param("user"));
		cgi_include ("../htdocs/login.html");
	}
	else
	{
		cgi_session_register_var("logged",result[1]);
		/* 修改系统用户跳转页面地址 */
		cgi_include("../htdocs/main.html");	
	}
	sqlite3_free_table(result);
	sqlite3_close(db);
	cgi_end();
	return 0;
}