简体   繁体   English

有没有办法使用SQL在IBM System i(aka iSeries / AS400)上更改用户密码?

[英]Is there a way to change user password on IBM System i (aka iSeries / AS400) using SQL?

I have a C#.NET application that must be able to change the user password on an IBM System i (iSeries / AS400) machine. 我有一个C#.NET应用程序,必须能够更改IBM System i(iSeries / AS400)计算机上的用户密码。 I am currently using the following code to perform this operation using IBM's proprietary cwbx.dll . 我目前正在使用以下代码使用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);
    }
}

This works well enough, but forces me (and all users of the application) to take a proprietary dependency on cwbx.dll . 这很好用,但迫使我(以及应用程序的所有用户)对cwbx.dll采取专有依赖。 I would like to eliminate this dependency. 我想消除这种依赖。

Is there any way to change the password using SQL similar to MS SQL Server's alter login mechanism? 有没有办法使用类似于MS SQL Server的alter login机制的SQL alter login

I know I can accomplish this with the IBM.Data.DB2.iSeries .NET data provider by invoking programs from SQL using the following code from Integrating DB2 Universal Universal Database for iSeries with for iSeries with Microsoft ADO .NET . 我知道我可以使用IBM.Data.DB2.iSeries .NET数据提供程序通过使用以下代码从SQL 集成DB2通用数据库for iSeries与iSeries与Microsoft ADO .NET来调用程序来完成此任务。

/// <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;
}

The problem with this technique is that I must have an existing connection before I can attempt to change a password. 这种技术的问题是我必须先有一个连接才能尝试更改密码。 Unfortunately, if the user's password has expired they cannot connect to the database ( iDB2CommErrorException ) and as a result cannot change their password. 不幸的是,如果用户的密码已过期,则无法连接到数据库( iDB2CommErrorException ),因此无法更改其密码。

Is there any way accomplish this without the cwbx.dll? 有没有办法在没有cwbx.dll的情况下实现这个目标?

To programmatically change expired passwords on an IBM i (aka System i / iSeries / AS400) from a .NET application without taking a dependency on a local installation of IBM i Access for Windows (for cwbx.dll), consider one of the following options. 要以编程方式从.NET应用程序更改IBM i(aka System i / iSeries / AS400)上的过期密码,而不依赖于IBM i Access for Windows的本地安装(对于cwbx.dll),请考虑以下选项之一。

  • Programmatically establish a Telnet connection to the IBM i and transmit a sequence of characters that mimics the user input necessary to perform a change password operation. 以编程方式建立与IBM i的Telnet连接,并传输一系列字符,模仿执行更改密码操作所需的用户输入。 *Note that this is insecure without further configuration. *请注意,如果没有进一步配置,这是不安全的。

  • IBM Toolbox for Java includes an OS/400 or i5/OS Java class that can be used in Java programs to change passwords. IBM Toolbox for Java包含一个OS / 400或i5 / OS Java类,可以在Java程序中用于更改密码。 The Java help for the class is available in iSeries Information Center a the following Web site: http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm 该类的Java帮助可在iSeries信息中心的以下Web站点中找到: http//publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm

    The following example demonstrates how to perform a change password operation on an expired password using the IBM Toolbox for Java . 以下示例演示如何使用IBM Toolbox for Java对过期的密码执行更改密码操作。 This can be invoked from a C# program using System.Diagnostics.Process.Start("java ChangeIBMiPassword hostname username oldpw newpw"); 这可以使用System.Diagnostics.Process.Start("java ChangeIBMiPassword hostname username oldpw newpw");从C#程序调用System.Diagnostics.Process.Start("java ChangeIBMiPassword hostname username oldpw newpw"); (assuming appropriate classpaths). (假设适当的类路径)。 Also note that it is possible to use Java API's directly from .NET with the IKVM.NET library . 另请注意,可以直接从.NET使用Java API和IKVM.NET库

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);
        }
    }
}
  • Write a secure web service that runs on the IBM i. 编写在IBM i上运行的安全Web服务。 This web service will accept parameters for username, current password and new password. 此Web服务将接受用户名,当前密码和新密码的参数。 When a user calls this web service, it will perform the change password operation on behalf of the calling program. 当用户调用此Web服务时,它将代表调用程序执行更改密码操作。

  • Write a secure web service that does not run on the IBM i. 编写一个不在IBM i上运行的安全Web服务。 This web service will accept parameters for username, current password and new password. 此Web服务将接受用户名,当前密码和新密码的参数。 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. 当用户调用此Web服务时,它将使用cwbx库代表调用程序执行更改密码操作。 This does not totally eliminate the dependency on cwbx.dll, but it lowers it to a single system. 这并不能完全消除对cwbx.dll的依赖,但它会将其降低到单个系统。

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

Write a stored procedure or function that invokes CHGUSRPRF. 编写一个调用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. 它需要在足够高的权限下运行(从而使系统暴露于额外的风险),但它很容易与SQL交互。 Seems like a very questionable idea. 似乎是一个非常值得怀疑的想法。

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

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