SmbFile URL path with password having an # - ntlm

I am using the JCIFS library and I have the samba file URL as
SmbFile file = new SmbFile("smb://domain;username:P#ssword#abc.com/share/filename.txt")
file.connect
Notice the password has an #. Samba file connect is failing giving an java.net.UnknownHostException. Other than parsing the URL and passing auth seperately using NtlmAuthentication, is there any other way...
In the Format URL I tried putting square brackets and that did not help.

URL Encode the password as below
URLEncoder.encode(password, "UTF-8");
this will encode your password to -P%40ssword
This called present encoding.Check this Wikipedia Link to learn more about present encoding.
But this is not a good practice.Create a NtlmPasswordAuthentication to set authentication details.
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, username, password);
String path ="abc.com/share/filename.txt";
SmbFile file = new SmbFile(path,auth);

I did UrlEncode of the password and that solved the problem.

Related

How to pass password only to HTTP request?

I am using JavaScript in the scripting engine in a program called Directory Opus. It seems to use a flavor of JavaScript more like MS JScript. I mention that because to say not all things JavaScript (ES6) will work with what it accepts. My question is this: in a HTTP request like the code I show should I be able to pass user credentials to the open command if only a password is required? This request is for VLC player and their instructions are to leave the username blank. If put the same URL in a browser it will prompt with a password once, I will put in the password “vlcremote”, leave the username blank and it will return the status. When I use with the syntax, I show, it returns an error when the open command uses “” as a username. If I put a random user name the request returns a limited result but denies access to the data it should give. Is there a better way to do this?
function getValues(webUrl)
{
var xhr = new ;
var url = webUrl;
xhr.open("GET", url, false, "", "vlcremote");
xhr.setRequestHeader("Content-type", "text/xml");
xhr.setRequestHeader("Authorization", "Basic")
xhr.send()
DOpus.Output(xhr.readyState)
var xmlText = xhr.responseText;
DOpus.Output(xmlText)
}
getValues("http://127.0.0.1:8080/requests/status.xml");

How to encode password in Silex?

I am writting a login app with Silex, but I have a problem with Silex password encoder. I read this in the silex document and got some code like this:
// find the encoder for a UserInterface instance
$encoder = $app['security.encoder_factory']->getEncoder($user);
// compute the encoded password for foo
$password = $encoder->encodePassword('foo', $user->getSalt());
But when I access my website in the first time, I don't have a $user varirable. Where can I get the $user varirable to encode my password?
UPDATE MY SOLUTION
Finally, I found a solution. This is my code to get encoded password:
$encoded = $app['security.default_encoder']->encodePassword($string, '')
It's best to answer your question by giving yourself an answer. This gives you the ability to mark it as completed. Other users won't havae to look back to your question to give you a solution.
For this case, you can set my answer as completing so that the question is closed.
Use this code to encrypt your string:
$encoded = $app['security.default_encoder']->encodePassword($string, '')
You can also use other ways to encrypt your passwords in Silex. They can be found over here.
The following code could be used to select another encryption:
$app['security.default_encoder'] = function ($app) {
return $app['security.encoder.pbkdf2'];
};

NodeJS write base64 encoded image to file

I have searched and tried all of the solutions at stackoverflow but none of them seems working at my instance. Basically I have an image, edited by html5 canvas, upload from client and I need to save it to disk, but unfortunately I can't open the file that I just saved. (I am using Windows 7)
My code:
var base64Data = req.body.image.replace(/^data:image\/(png|gif|jpeg);base64,/,'');
require('fs').writeFile('public/aboutToGiveUp.png', new Buffer(base64Data, 'base64'));
Got same bug, it's because of incorrect url path, You may added app.use("/", express.static(path.join(__dirname, 'public')));, so no need to add the public in the url, check your url path once.
working sample :
url = req.protocol+'://'+req.headers.host+"/"+filename;
url = req.protocol+'://'+req.headers.host+"/images/"+filename; // its in public/images
Try using ./public/aboutToGiveUp.png or make sure that the path is relative to the file containing this code.

Router with base64 generated param

I am trying to send a parameter after convert it to the base 64 the definition of the geddy.js route :
router.get(routing_prefix+'/gogetthecart/:data').to('Main.gogetthecart');
In the client side, javascript, I generate a base64 json data var jsonb64 = btoa(JSON.stringify(params)); after that I call the url that will somthing like this
http://www.mydomain.com//gogetthecart/GVudGl...aWNo=
I got Error: 404 Not Found.. But If I delete manually the = from the end of data that work
Solved by the community in the git repos issues https://github.com/geddy/geddy/issues/556 as Kieran said
I looked into adding support for base64 encoded vars to Barista
directly, but some characters in the b64 spec are reserved in the URI
spec. I don't feel comfortable making that the default behaviour.
However! You can simply override the behaviour to support this use
case:
router
.get( routing_prefix+'/gogetthecart/:data')
.to('Main.gogetthecart')
.where({
data: /[\w\-\/+]+={0,2}/ // base64-safe regex condition
})
and that should do the trick!
I added a test here:
https://github.com/kieran/barista/blob/master/tests/barista.test.js#L812

Flickr API: getInfo on Guest Pass photos?

So, Flickr Guest Pass URLs are in the following format:
www.flickr.com/x/t/[numericID]/gp/[userID]/[alphanumericID]
Now if I try an API call of the following form:
API_KEY = 'myapikey'
PHOTO_ID = '[numericID]'
SECRET = '[alphanumericID]'
url = 'http://api.flickr.com/services/rest/?method=flickr.photos.getInfo' +
'&api_key=%s&photo_id=%s&secret=%s' % (API_KEY, PHOTO_ID, SECRET)
I do get some photo information back, but for completely the wrong photograph!
It may be relevant that the photo ID in my Guest Pass starts "00": in the info returned by the API, the initial zeros have been chopped off.
Am I supplying the right information to getInfo()?
Figured it out in the end. The Photo ID is in the URL that the Guest Pass resolves to. The secret is in the URL of the jpeg of the photo itself.
So, for example, on a photo:
flickr.com/curiouskiwi/5203020393
The photo ID is the final part of the URL. If you view the photo, you find that the JPG of the URL is
farm6.static.flickr.com/5045/5203020393_f41c8d7fe7_z.jpg
And from that, you know the secret is f41c8d7fe7.

Resources