我正在使用以下代码来检查提供的参数是否正确用于绑定..
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = your_server_ip_address
ldap.port = 389
ldap.auth "joe_user", "opensesame"
if ldap.bind
# authentication succeeded
else
# authentication failed
end
如果用户和密码不正确,则返回 false,但如果主机或端口号不正确,则显示错误(异常)
no connection to server (Net::LDAP::LdapError)
我还想捕获此错误,并希望分别为 incoreect 用户/密码和不正确的端口/主机名显示错误消息。我怎样才能做到这一点