private static void ImportUsers() { string pathOfUsersConf = allConf["users"][0][0] as string; if (File.Exists(pathOfUsersConf)) { string usersText = File.ReadAllText(pathOfUsersConf); usersText = usersText.Replace("\r\n", "\n"); string[] usersArray = usersText.Split('\n'); string[][] users = ReadStrs_Split(usersArray); foreach (string[] user in users) { if (user.Length >= 1) { TunnelUser newUser = new TunnelUser(user[0]); if (user.Length >= 2) { newUser.Password = user[1]; } if (user.Length >= 3) { if (int.TryParse(user[2], out int speedlimit)) { newUser.SpeedLimit = speedlimit; } } Conf.Users.Add(newUser.ID, newUser); } } } }
private bool Authenticate(TcpClient client) { TunnelUser firstUser = Conf.Users.Values.First(); string id = firstUser.ID; string pswd = firstUser.Password; WriteStr(client, id + ':' + pswd); string result = ReadStr(client); if (result == "valid") { return(true); } else if (result == "valid") { return(false); } else { return(false); } }
protected override bool Authenticate(Socket socket2Server) { DateTime now; if (Conf.IsDebug) { now = DateTime.Now; } bool result = false; if (socket2Server != null) { if (base.Authenticate(socket2Server)) { if (Conf.Users.Count > 0) { TunnelUser firstUser = Conf.Users.Values.First(); string id = firstUser.ID; string pswd = firstUser.Password; WriteStr(socket2Server, id + ':' + pswd); string reply = ReadStr(socket2Server); result = reply == "valid"; } } } if (Conf.IsDebug) { double sec = (DateTime.Now - now).TotalSeconds; if (sec > Conf.DebugTimeThreshold) { Console.WriteLine("Time for Authen_ClientRelay.Authenticate(Socket) is {0} s", sec); } } return(result); }