/[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.75 by sysadm, Fri Dec 19 06:16:27 2025 UTC Revision 1.80 by sysadm, Sun Jan 4 13:24:00 2026 UTC
# Line 3  Line 3 
3   * login   * login
4   *   - user authentication and online status manager   *   - user authentication and online status manager
5   *   *
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7   */   */
8    
9  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 41  int bbs_login(void) Line 41  int bbs_login(void)
41  {  {
42          char username[BBS_username_max_len + 1];          char username[BBS_username_max_len + 1];
43          char password[BBS_password_max_len + 1];          char password[BBS_password_max_len + 1];
44          int i = 0;          int i;
         int ok = 0;  
45          int ret;          int ret;
46    
47          for (; !SYS_server_exit && !ok && i < BBS_login_retry_times; i++)          for (i = 0; !SYS_server_exit && i < BBS_login_retry_times; i++)
48          {          {
49                    clrtoeol();
50                  prints("\033[1;33m请输入帐号\033[m(试用请输入`\033[1;36mguest\033[m', "                  prints("\033[1;33m请输入帐号\033[m(试用请输入`\033[1;36mguest\033[m', "
51                             "注册请输入`\033[1;31mnew\033[m'): ");                             "注册请输入`\033[1;31mnew\033[m'): ");
52                  iflush();                  iflush();
# Line 59  int bbs_login(void) Line 59  int bbs_login(void)
59                  if (strcmp(username, "guest") == 0)                  if (strcmp(username, "guest") == 0)
60                  {                  {
61                          load_guest_info();                          load_guest_info();
62                            log_common("User [%s] authenticated successfully", username);
63                          return 0;                          return 0;
64                  }                  }
65    
66                  if (strcmp(username, "new") == 0)                  if (strcmp(username, "new") == 0)
67                  {                  {
68                          display_file(DATA_REGISTER, 1);                          display_file(DATA_REGISTER, 1);
   
69                          return -1;                          return -1;
70                  }                  }
71    
72                  if (username[0] != '\0')                  if (username[0] != '\0')
73                  {                  {
74                            clrtoeol();
75                          prints("\033[1;37m请输入密码\033[m: ");                          prints("\033[1;37m请输入密码\033[m: ");
76                          iflush();                          iflush();
77    
# Line 87  int bbs_login(void) Line 87  int bbs_login(void)
87                                  ret = 0;                                  ret = 0;
88                          }                          }
89    
90                          ok = (ret == 0);                          if (ret == 0)
91                            {
92                                    log_common("User [%s] authenticated successfully", username);
93                                    return 0;
94                            }
95    
96                            log_common("User [%s] authentication failed (%d/%d)", username,
97                                               i + 1, BBS_login_retry_times);
98                          iflush();                          iflush();
99                  }                  }
100          }          }
101    
102          if (!ok)          display_file(DATA_LOGIN_ERROR, 1);
103          {          return -1;
                 display_file(DATA_LOGIN_ERROR, 1);  
                 return -1;  
         }  
   
         return 0;  
104  }  }
105    
106  int check_user(const char *username, const char *password)  int check_user(const char *username, const char *password)
# Line 324  int check_user(const char *username, con Line 326  int check_user(const char *username, con
326                  goto cleanup;                  goto cleanup;
327          }          }
328    
         if (!SSH_v2 && checklevel2(&BBS_priv, P_MAN_S))  
         {  
                 prints("\033[1;31m非普通账户必须使用SSH方式登录\033[m\r\n");  
                 ret = 1;  
                 goto cleanup;  
         }  
   
329          ret = load_user_info(db, BBS_uid);          ret = load_user_info(db, BBS_uid);
330    
331          switch (ret)          switch (ret)
332          {          {
333          case 0: // Login successfully          case 0: // Login successfully
334                    if (!SSH_v2 && checklevel2(&BBS_priv, P_MAN_S))
335                    {
336                            prints("\033[1;31m非普通账户必须使用SSH方式登录\033[m\r\n");
337                            ret = 1;
338                            goto cleanup;
339                    }
340                  break;                  break;
341          case -1: // Load data error          case -1: // Load data error
342                  prints("\033[1;31m读取用户数据错误...\033[m\r\n");                  prints("\033[1;31m读取用户数据错误...\033[m\r\n");
343                  ret = -1;                  ret = -1;
344                  goto cleanup;                  goto cleanup;
345          case -2: // Enforce update user agreement          case -2: // Enforce update user agreement
346                    if (!SSH_v2 && checklevel2(&BBS_priv, P_MAN_S))
347                    {
348                            prints("\033[1;31m非普通账户必须使用SSH方式登录\033[m\r\n");
349                            ret = 1;
350                            goto cleanup;
351                    }
352                  ret = 2;                  ret = 2;
353                  goto cleanup;                  goto cleanup;
354          case -3: // Dead          case -3: // Dead


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

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