Perforce: 有关Your session has expired, please login again的解决办法

使用Perforce API来sync Server上的文件,发现经过12小时之后总是报“Your session has expired, please login again”的错误,检查用户名和密码均正确,代码也是按照perforce的example写的,不存在什么问题,但是就是登录不了,即便调用了Connection.Login函数,同样也不能登录。


最后在尝试无数次之后,发现和SERVER的security level设置有关。

当SERVER的security level为3的时候,就不能通过直接设置password在Option中的方法来登录,即:

Connection con = rep.Connection;

Options options = new Options();
options["Password"] = “password”;

con.Login(“password”, options);


如果这样写代码,就算传递给login函数的密码是正确的,也不能登录,因为SERVER的security level被设置为3,如果发现Options中的Password字段有值,就直接拒绝连接请求!


因此,需要讲代码改成:

Connection con = rep.Connection;

Options options = new Options();

con.Login(“password”, options);


或者干脆不要option:

Connection con = rep.Connection;

Options options = new Options();

con.Login(“password”,null);


这样就可以成功登录SERVER了。


附录一段perforce Server中有关security level的描述:

-----------------------------------------------------------------------------

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 are not required, and

password strength is not enforced. 
To ensure that all users have passwords, use security level 1.

Users of old client programs can still enter weak passwords.

To ensure that all users have 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 that all users have 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 are defined below.

Security level
Server behavior

(or unset) 
Legacy support: passwords are not required. If passwords are

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 are unaffected. 

Strong passwords are required for users of post-2003.2 Perforce

client programs, but existing passwords are not reset.

Pre-2003.2 Perforce client programs can set passwords with p4

passwd or in the p4 user form, but password strength is not

enforced.

Users with passwords can use either their P4PASSWD setting or the

p4 login command for ticket-based authentication. 

All unverified strength passwords must be changed.

Users of pre-2003.2 client programs cannot set passwords.

Users of 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 are no longer stored in (or read from) the

registry. (Storing P4PASSWD as an environment variable is

supported, but passwords set with p4 set P4PASSWD are ignored.)

Users who have 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. 

All password-based authentication is rejected.

Users must use ticket-based authentication (p4 login).

If you have scripts that rely on passwords, use 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 be passed to

Perforce commands as though it were a password (that is, 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 is at least eight characters

long, and at least two of the following are true:

The password contains uppercase letters.

The password contains lowercase letters.

The password contains nonalphabetic characters.

For example, the passwords a1b2c3d4, A1B2C3D4, aBcDeFgH are

considered strong.



你可能感兴趣的:(Perforce: 有关Your session has expired, please login again的解决办法)