Using the Perforce API to sync files on the server, it is found that after 12 hours it is always reported that "Your session has expired, please login again" error, check the user name and password are correct, Code is written according to Perforce example, there is no problem, but it is not logged in, even if the Connection.login function is called, the same can not log in.
Finally, after countless attempts, the discovery is related to the security level settings of the server.
When the security level of the server is 3, it is not possible to log in directly by setting the password method in option, i.e.:
Connection con = Rep. Connection;
Options options = new options ();
options["Password"] = "Password";
Con. Login ("Password", options);
If this code is written, even if the password passed to the login function is correct, you cannot log in because the security level of the server is set to 3, and if the password field in the options is found to have a value, the connection request is rejected directly.
Therefore, the code needs to be changed to:
Connection con = Rep. Connection;
Options options = new options ();
Con. Login ("Password", options);
Or simply do not option:
Connection con = Rep. Connection;
Options options = new options ();
Con. Login ("password", null);
This will allow you to successfully log on to the server.
Appendix A description of the security level in Perforce server:
-----------------------------------------------------------------------------
Server security Levels
Perforce superusers can configure server-wide password usage
requirements, password strength enforcement, and supported
Methods of User/server authentication by setting the security
Counter. To change the security counter, issue the command:
P4 counter-f Security Seclevel
Where Seclevel is 0, 1, 2, or 3. After setting the counter, stop
and restart the server.
Choosing a server Security level
The default security level is 0:passwords was not required, and
Password strength is not enforced.
To ensure the all users has passwords, use security Level 1.
Users of old client programs can still enter weak passwords.
To ensure the all users has strong passwords, use security
Level 2. Old Perforce Software continues to work, but users of
Old Perforce client software must change their password to a
Strong password by using a Perforce client program at Release
2003.2 or above.
To require the all users has strong passwords, and to require
The use of session-based authentication, use security Level 3 and
Current Perforce client software.
Level 0 corresponds to pre-2003.2 server operation. Levels 1 and
2 were designed for support of Legacy Client software. Level 3
Affords the highest degree of security.
The Perforce server security levels and their effects on the
Behavior of Perforce client programs is defined below.
Security level
Server behavior
0
(or unset)
Legacy Support:passwords is not required. If Passwords is
Used, password strength is not enforced.
Users with passwords can use either their p4passwd setting or the
P4 login command for ticket-based authentication.
Users of old Perforce client programs is unaffected.
1
Strong passwords is required for users of post-2003.2 Perforce
Client programs, but existing passwords is not reset.
Pre-2003.2 Perforce client programs can set passwords with P4
passwd or in the P4 user form, but password strength are not
Enforced.
Users with passwords can use either their p4passwd setting or the
P4 login command for ticket-based authentication.
2
All unverified strength passwords must is changed.
Users of pre-2003.2 client programs cannot set passwords.
Users of the client programs at release 2003.2 or higher must use P4
passwd and enter their passwords at the prompt. Setting passwords
With the P4 user form or the P4 passwd-o oldpass-p Newpass
command is prohibited.
On Windows, passwords is no longer stored in (or read from) the
Registry. (Storing p4passwd as an environment variable are
Supported, but passwords set with P4 set P4PASSWD is ignored.)
The Users who has set strong passwords with a 2003.2 or higher
Perforce client program can use either their p4passwd setting for
password-based authentication, or the P4 login command for
ticket-based authentication.
3
All password-based authentication are rejected.
Users must use ticket-based authentication (P4 login).
If You have scripts this rely on passwords, use the P4 login to
Create a ticket valid for the user running the script, or use P4
Login-p to display the value of a ticket that can is passed to
Perforce commands as though it were a password (that's, either
From the command line, or by setting P4PASSWD to the value of the
Valid ticket).
Password Strength
Certain combinations of server security level and Perforce client
Software releases require users to set "strong" passwords. A
Password is considered strong if it's at least eight characters
Long, and at least, the following is true:
The password contains uppercase letters.
The password contains lowercase letters.
The password contains nonalphabetic characters.
For example, the passwords a1b2c3d4, A1B2C3D4, ABCDEFGH is
Considered strong.
Related Article:
Principles and solutions of how to keep the SESSION not expired in PHP
Asp.net session usage and expired instance code