简体   繁体   English

Oracle 密码到期和宽限期处理使用 C# 客户端

[英]Oracle password expiry and grace period handling using C# client

I have a c# client and I am using oracle 10g database.我有一个 c# 客户端,我正在使用 oracle 10g 数据库。

My query is:我的查询是:

  1. Is the expiry grace period over and above exiry date?到期宽限期是否超过到期日?
  2. When the user is in grace period can the user change his/her password using query ALTER USER XYZ IDENTIFIED BY SOMEPWD or he still need to contact DBA.当用户处于宽限期时,用户可以使用查询ALTER USER XYZ IDENTIFIED BY SOMEPWD更改他/她的密码,或者他仍然需要联系 DBA。
  3. How can I handle oracle warning ORA-28002(when the user is in grace period) in c# client.如何在 c# 客户端中处理 oracle 警告 ORA-28002(当用户处于宽限期时)。 does it at all gets transmitted to c# client.它是否会被传输到 c# 客户端。 Would it still be handled as exception (try-catch).是否仍将其作为异常处理(try-catch)。
  4. When the password has already expired, is it that only DBA can change your password.当密码已经过期时,是否只有DBA才能更改您的密码。
  5. does the account gets locked also when expiry date has exceeded beyond grace period.当到期日期超过宽限期时,帐户是否也会被锁定。

Please note I am not sys dba so I cannot access dba_users or dba_profiles.请注意,我不是 sys dba,因此我无法访问 dba_users 或 dba_profiles。

Thanks in advance.提前致谢。

Finally I have found solution to my problem.最后我找到了解决我的问题的方法。 Here are the points for everyones information:以下是供大家参考的要点:

1) Is the expiry grace period over and above exiry date? 1) 到期宽限期是否超过到期日?

Answer: Yes its over and above.回答:是的,超过了。

2) When the user is in grace period can the user change his/her password using query "ALTER USER XYZ IDENTIFIED BY SOMEPWD" or he still need to contact DBA. 2)当用户处于宽限期时,用户可以使用查询“ALTER USER XYZ IDENTIFIED BY SOMEPWD”更改他/她的密码,或者他仍然需要联系DBA。

Answer: No user cannot run this query because it would first require to be connected to database.答:没有用户不能运行此查询,因为它首先需要连接到数据库。 With expired password you cannot connect.密码过期无法连接。

3) How can I handle oracle warning ORA-28002(when the user is in grace period) in c# client. 3)如何在 c# 客户端中处理 oracle 警告 ORA-28002(当用户处于宽限期时)。 does it at all gets transmitted to c# client.它是否会被传输到 c# 客户端。 Would it still be handled as exception (try-catch).是否仍将其作为异常处理(try-catch)。

Answer: ORA-28002 error can be handled in c# client as OracleClientInfoMessage.答:ORA-28002 错误可以在 c# 客户端作为 OracleClientInfoMessage 处理。 Here is the sample code.这是示例代码。

try
{
    OracleConnection conn = new OracleConnection("User ID=" + uid + ";Password=" + pwd + ";SERVER=" + server);
    conn.InfoMessage += new OracleInfoMessageEventHandler(GetOracleWarningInfoMessage);        
    conn.Open();
    return ConnectionStatus.OK;
}
catch (System.Data.OracleClient.OracleException ex)
{
    Logger.Error(ex);
    switch (ex.Code)
    {
        case 1005: //null password given
            errmsg = "Invalid password";
            return ConnectionStatus.InvalidUserPwd;
        case 1017: //invalid username/password
            errmsg = "Invalid username/password";
            return ConnectionStatus.InvalidUserPwd;
        case 1040: //invalid character in password
            errmsg = "Invalid password";
            return ConnectionStatus.InvalidUserPwd;
        case 28000://account locked
            errmsg = "Account locked. Contact DBA or wait for PASSWORD_LOCK_TIME";
            return ConnectionStatus.Locked;
        case 28001://password expired                       
            errmsg = "Password expired. Contact DBA";
            return ConnectionStatus.Expired;
        default:
            errmsg = ex.Message;
            return ConnectionStatus.Failed;
    }
}

4) When the password has already expired, is it that only DBA can change your password. 4) 密码已经过期,是不是只有DBA才能修改密码。

Answer: The user can change the password himself.答:用户可以自己修改密码。 If you are using SQLPlus or ODP.net driver you will get a prompt.如果您使用的是 SQLPlus 或 ODP.net 驱动程序,您将收到提示。 However if you are using OracleClient (Microsoft) driver you will not be able to since it lacks the OpenWithNewPassword function(which allows to change password before established connection).但是,如果您使用的是 OracleClient (Microsoft) 驱动程序,您将无法使用它,因为它缺少 OpenWithNewPassword 功能(允许在建立连接之前更改密码)。 Probably becuase of non co-operation movement between Mircosoft and Oracle.可能是因为 Mircosoft 和 Oracle 之间的非合作运动。 OpenWithNewPassword support is only available in Driver ODP(OracleDataProvider) and native OCL. OpenWithNewPassword 支持仅在 Driver ODP(OracleDataProvider) 和本机 OCL 中可用。 For details refer to link: MSDN or Oracle .有关详细信息,请参阅链接: MSDNOracle

5) does the account gets locked also when expiry date has exceeded beyond grace period. 5) 当到期日超过宽限期时,账户是否也会被锁定。

Answer: No it gets Expired not Locked.答:不,它会过期而不是锁定。

Yes the grace period is above the expiry date and if i am not mistaken this is how it happens, you have expiry period of 30 days and a grace of 5. Now post the 30 day period the user has expired and now you enter into the grace period which is significant from the first login made after the 30 day limit.是的,宽限期高于到期日,如果我没记错的话,这就是它的发生方式,您有 30 天的到期期限和 5 天的宽限期。现在发布用户已到期的 30 天期限,现在您进入宽限期,从 30 天限制后的第一次登录开始算起。 Now in these 5 days you have the option to change your password.现在在这 5 天内,您可以选择更改密码。

Oracle implicitly allows a user to change its own password, so you could change it within the grace period else you will need a different user which has the privileges to change the password of another user. Oracle 隐式允许用户更改自己的密码,因此您可以在宽限期内更改它,否则您将需要一个有权更改另一个用户密码的不同用户。

If you have exceeded even the grace period the account gets locked and will get unlocked on a password change.如果您甚至超过了宽限期,则该帐户将被锁定,并会在更改密码时解锁。

Regarding point 3: It has been our experience that ODP.Net does not throw an exception nor trigger the OracleInfoMessageEventHandler when ORA-28002 occurs.关于第 3 点:根据我们的经验,ODP.Net 在 ORA-28002 发生时不会抛出异常也不会触发 OracleInfoMessageEventHandler。 Google searches only show that this is a bug in ODP, but no reference to it being fixed.谷歌搜索只显示这是 ODP 中的一个错误,但没有提到它正在修复。

Here is our workaround... We created a stored function that looks at DBA_USERS to determine the expiry date of a given user's password.这是我们的解决方法...我们创建了一个存储的 function,它查看 DBA_USERS 以确定给定用户密码的到期日期。 This function is created to run in the authorization context of the creator (which has privs to see this DBA view).此 function 被创建为在创建者的授权上下文中运行(具有查看此 DBA 视图的权限)。

create or replace function GetExpDate(vUser in varchar2) return DATE
AUTHID DEFINER
as
expDate date;
begin
   select nvl(expiry_date, sysdate+100) 
   into expDate 
   from dba_users
   where username = vUser;

   return expDate;

exception
when others then
   return sysdate+100;
end; 

After the user logins in successfully, we check this function to see if they are close to expiration and if so prompt for them to change their password.用户登录成功后,我们检查此 function 以查看他们是否接近到期,如果接近则提示他们更改密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM