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


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

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