/[LeafOK_CVS]/lbbs/src/login.c
ViewVC logotype

Diff of /lbbs/src/login.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 by sysadm, Fri Oct 22 15:20:32 2004 UTC Revision 1.6 by sysadm, Wed Mar 2 16:33:49 2005 UTC
# Line 27  login_fail () Line 27  login_fail ()
27    char temp[256];    char temp[256];
28    
29    strcpy (temp, app_home_dir);    strcpy (temp, app_home_dir);
30    strcat (temp, "data/login_error.dat");    strcat (temp, "data/login_error.txt");
31    display_file (temp);    display_file (temp);
32    
33    sleep (1);    sleep (1);
# Line 53  bbs_login () Line 53  bbs_login ()
53        count++;        count++;
54    
55        if (strcmp (username, "guest") == 0)        if (strcmp (username, "guest") == 0)
56          return 1;          {
57              load_guest_info ();
58              return 0;
59            }
60    
61          if (strcmp (username, "new") == 0)
62            {
63              if (user_register () == 0)
64                return 0;
65              else
66               return -2;
67            }
68    
69        if (strlen (username) > 0)        if (strlen (username) > 0)
70          {          {
# Line 63  bbs_login () Line 74  bbs_login ()
74    
75            str_input (password, 19, 1);            str_input (password, 19, 1);
76    
77            ok = (check_user (username, password) == 0);            ok = (check_user (username, password) == 0);
78          }          }
79        if (count >= 3 && !ok)        if (count >= 3 && !ok)
80          {          {
# Line 101  check_user (char *username, char *passwo Line 112  check_user (char *username, char *passwo
112      }      }
113    
114    sprintf (sql,    sprintf (sql,
115             "select UID,p_login from user_list where username='%s' "             "select UID,username,p_login from user_list where username='%s' "
116             "and (password=MD5('%s') or password=PASSWORD('%s')) and "             "and (password=MD5('%s') or password=PASSWORD('%s')) and "
117             "enable", username, password, password);             "enable", username, password, password);
118    if (mysql_query (db, sql) != 0)    if (mysql_query (db, sql) != 0)
# Line 117  check_user (char *username, char *passwo Line 128  check_user (char *username, char *passwo
128    if (row = mysql_fetch_row (rs))    if (row = mysql_fetch_row (rs))
129      {      {
130        BBS_uid = atol (row[0]);        BBS_uid = atol (row[0]);
131        if (atoi (row[1]) == 0)        strcpy (BBS_username, row[1]);
132          if (atoi (row[2]) == 0)
133          {          {
134            mysql_free_result (rs);            mysql_free_result (rs);
135            mysql_close (db);            mysql_close (db);
# Line 134  check_user (char *username, char *passwo Line 146  check_user (char *username, char *passwo
146        sprintf (sql,        sprintf (sql,
147                 "insert delayed into user_err_login_log"                 "insert delayed into user_err_login_log"
148                 "(username,password,login_dt,login_ip) values"                 "(username,password,login_dt,login_ip) values"
149                 "('%s','%s',now(),'%s')",                 "('%s','%s',now(),'%s')", username, password, hostaddr_client);
                username, password, hostaddr_client);  
150        if (mysql_query (db, sql) != 0)        if (mysql_query (db, sql) != 0)
151          {          {
152            log_error ("Insert into user_err_login_log failed\n");            log_error ("Insert into user_err_login_log failed\n");
# Line 150  check_user (char *username, char *passwo Line 161  check_user (char *username, char *passwo
161      }      }
162    mysql_free_result (rs);    mysql_free_result (rs);
163    
164    BBS_passwd_complex = verify_pass_complexity(password, username, 6);    BBS_passwd_complex = verify_pass_complexity (password, username, 6);
165    
166    ret = load_user_info (db, BBS_uid);    ret = load_user_info (db, BBS_uid);
167    
   mysql_close (db);  
   
168    switch (ret)    switch (ret)
169      {      {
170      case 0:                     //Login successfully      case 0:                     //Login successfully
# Line 169  check_user (char *username, char *passwo Line 178  check_user (char *username, char *passwo
178      case -2:                    //Unused      case -2:                    //Unused
179        return 0;        return 0;
180        break;        break;
181      case -3:      case -3:                    //Dead
182        prints ("\033[1;31m很遗憾,您已经永远离开了我们的世界!\033[m\r\n");        prints ("\033[1;31m很遗憾,您已经永远离开了我们的世界!\033[m\r\n");
183        iflush ();        iflush ();
184        return 1;        return 1;
# Line 177  check_user (char *username, char *passwo Line 186  check_user (char *username, char *passwo
186        return -2;        return -2;
187      }      }
188    
189      mysql_close (db);
190    
191    return 0;    return 0;
192  }  }
193    
# Line 237  load_user_info (MYSQL * db, long int BBS Line 248  load_user_info (MYSQL * db, long int BBS
248      {      {
249        BBS_auth_uid = atol (row[0]);        BBS_auth_uid = atol (row[0]);
250      }      }
251      else
252        {
253          BBS_auth_uid = 0;
254        }
255    mysql_free_result (rs);    mysql_free_result (rs);
256    
257    sprintf (sql,    sprintf (sql,
258     "insert delayed into user_login_log"             "insert delayed into user_login_log"
259     "(uid,login_dt,login_ip) values(%ld"             "(uid,login_dt,login_ip) values(%ld"
260     ",now(),'%s')",             ",now(),'%s')", BBS_uid, hostaddr_client);
    BBS_uid, hostaddr_client);  
261    if (mysql_query (db, sql) != 0)    if (mysql_query (db, sql) != 0)
262      {      {
263        log_error ("Insert into user_login_log failed\n");        log_error ("Insert into user_login_log failed\n");
# Line 251  load_user_info (MYSQL * db, long int BBS Line 265  load_user_info (MYSQL * db, long int BBS
265      }      }
266    
267    load_priv (db, &BBS_priv, BBS_uid, BBS_auth_uid,    load_priv (db, &BBS_priv, BBS_uid, BBS_auth_uid,
268      (!BBS_passwd_complex ? S_MAN_M : S_NONE) |               (!BBS_passwd_complex ? S_MAN_M : S_NONE) |
269      (BBS_auth_uid ? S_NONE : S_MAIL));               (BBS_auth_uid ? S_NONE : S_MAIL));
270    
271    BBS_last_access_tm = BBS_login_tm = time (0);    BBS_last_access_tm = BBS_login_tm = time (0);
272    BBS_last_sub_tm = time (0) - 60;    BBS_last_sub_tm = time (0) - 60;
273    
274    sprintf (sql,    sprintf (sql,
275     "update user_pubinfo set visit_count=visit_count+1,"             "update user_pubinfo set visit_count=visit_count+1,"
276     "last_login_dt=now() where uid=%ld", BBS_uid);             "last_login_dt=now() where uid=%ld", BBS_uid);
277    if (mysql_query (db, sql) != 0)    if (mysql_query (db, sql) != 0)
278      {      {
279        log_error ("Update user_pubinfo failed\n");        log_error ("Update user_pubinfo failed\n");
# Line 268  load_user_info (MYSQL * db, long int BBS Line 282  load_user_info (MYSQL * db, long int BBS
282    
283    return 0;    return 0;
284  }  }
285    
286    int
287    load_guest_info (MYSQL * db, long int BBS_uid)
288    {
289      MYSQL_RES *rs;
290      MYSQL_ROW row;
291    
292      db = (MYSQL *) db_open ();
293      if (db == NULL)
294        {
295          return -1;
296        }
297    
298      strcpy (BBS_username, "guest");
299    
300      load_priv (db, &BBS_priv, 0, 0, S_NONE);
301    
302      BBS_last_access_tm = BBS_login_tm = time (0);
303      BBS_last_sub_tm = time (0) - 60;
304    
305      mysql_close (db);
306    
307      return 0;
308    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1