7

我有一个 C#.NET 应用程序,它必须能够更改 IBM System i (iSeries / AS400) 机器上的用户密码。我目前正在使用以下代码使用 IBM 专有的cwbx.dll执行此操作。

using cwbx;

public void ChangePassword(string system, string user, string currentPassword, string newPassword)
{
    AS400System as400 = new AS400System();
    as400.Define(system);
    try
    {
        as400.ChangePassword(user, currentPassword, newPassword);
    }
    finally
    {
        as400.Disconnect(cwbcoServiceEnum.cwbcoServiceAll);
    }
}

这工作得很好,但迫使我(和应用程序的所有用户)对cwbx.dll采取专有依赖。我想消除这种依赖。

有没有办法使用类似于 MS SQL Serveralter login机制的 SQL 更改密码?

我知道我可以使用IBM.Data.DB2.iSeries .NET 数据提供程序来完成此操作,方法是使用Integrating DB2 Universal Universal Database for iSeries with for iSeries with Microsoft ADO .NET中的以下代码从 SQL 调用程序。

/// <summary>
/// Call a program directly on the iSeries with parameters
/// </summary>
public string CallPgm(string cmdtext)
{
    string rc = " ";

    // Construct a string which contains the call to QCMDEXC.
    // Because QCMDEXC uses single quote characters, we must
    // delimit single quote characters in the command text
    // with an extra single quote.
    string pgmParm = "CALL QSYS/QCMDEXC('"
    + cmdtext.Replace("'", "''")
    + "', "
    + cmdtext.Length.ToString("0000000000.00000")
    + ")";

    // Create a command to execute the program or command.
    iDB2Command cmd = new iDB2Command(pgmParm, _connection);
    try
    {
        cmd.ExecuteNonQuery();
    }
    catch (iDB2Exception ex)
    {
        rc = ex.Message;
    }

    // Dispose the command since we're done with it.
    cmd.Dispose();

    // Return the success or failure of the call.
    return rc;
}

这种技术的问题是我必须有一个现有的连接才能尝试更改密码。不幸的是,如果用户的密码已过期,他们将无法连接到数据库 ( iDB2CommErrorException),因此无法更改他们的密码。

没有 cwbx.dll 有没有办法做到这一点?

4

2 回答 2

4

要以编程方式从 .NET 应用程序更改 IBM i(又名 System i / iSeries / AS400)上的过期密码,而不依赖于IBM i Access for Windows(用于 cwbx.dll)的本地安装,请考虑以下选项之一.

  • 以编程方式建立到 IBM i 的 Telnet 连接并传输一系列字符,这些字符模仿执行更改密码操作所需的用户输入。*请注意,如果没有进一步配置,这是不安全的。

  • IBM Toolbox for Java 包括一个 OS/400 或 i5/OS Java 类,可在 Java 程序中用于更改密码。该类的 Java 帮助可在以下 Web 站点的 iSeries 信息中心获得:http: //publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm

    以下示例演示如何使用IBM Toolbox for Java对过期密码执行更改密码操作。这可以使用System.Diagnostics.Process.Start("java ChangeIBMiPassword hostname username oldpw newpw");(假设有适当的类路径)从 C# 程序中调用。另请注意,可以通过IKVM.NET 库直接从 .NET 使用 Java API 。

import com.ibm.as400.access.AS400;

public class ChangeIBMiPassword {
    public static void main(String[] args) {
        if (args.length < 4)
            System.exit(-1);

        String host = args[0];
        String user = args[1];
        String oldpw = args[2];
        String newpw = args[3];

        AS400 sys = new AS400(host, user);  
        try {
            sys.changePassword(oldpw, newpw);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}
  • 编写在 IBM i 上运行的安全 Web 服务。此 Web 服务将接受用户名、当前密码和新密码的参数。当用户调用此 Web 服务时,它将代表调用程序执行更改密码操作。

  • Write a secure web service that does not run on the IBM i. This web service will accept parameters for username, current password and new password. When a user calls this web service, it will use the cwbx library to perform the change password operation on behalf of the calling program. This does not totally eliminate the dependency on cwbx.dll, but it lowers it to a single system.

http://www-01.ibm.com/support/docview.wss?uid=nas10043a8b0e0544f1386256ba100659bcd

于 2013-04-03T15:42:12.827 回答
0

Write a stored procedure or function that invokes CHGUSRPRF. It would need to run under high enough authority (and thereby expose the system to additional risk), but it'd then be easy to interact with SQL. Seems like a very questionable idea.

于 2014-04-06T14:47:06.333 回答