sgr123
sgr123

Reputation: 45

Java username password check

There is a specific server IP address that requires authentication I usually access through cmd line "ftp x.y.z.0" enter my u/n, enter my p/w and I'm in. I want to have my program ask for user credentials, check if they can log in to this server/IP address and simply return true if they can, false if not. I'm don't own this server or know really much about it, I just need to know if the end user of my application has access to it or not. I don't want to use any external packages, only what is available in the standard java library if at all possible. Any help with this is appreciated.

My most recent attempt:

 URL url = new URL("ftp://1.0.0.0/");
 URLConnection uc = url.openConnection();
 String userpass = username + ":" + password;
 String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
 uc.setRequestProperty ("Authorization", basicAuth);
 InputStream in = uc.getInputStream();

Not sure exactly what it's doing but it seems to give same response no matter what I put in for the username and password strings.

Upvotes: 3

Views: 1081

Answers (1)

jdevelop
jdevelop

Reputation: 12296

For checking login via trying to connect to FTP server you will need to use sockets and do lot of parsing of FTP protocol and authentication stuff. So I'd suggest to use Commons Net, which also would allow you to deal with other authentication stuff in over HTTP/NNTP/etc.

Upvotes: 1

Related Questions