Add session to cache with both hostname and address.
[cyberduck.git] / source / ch / cyberduck / core / DataProtectorPasswordStore.cs
bloba1b6a78ee1d168db9f8d38f8a95c1b566befcfb9
1 //
2 // Copyright (c) 2010-2014 Yves Langisch. All rights reserved.
3 // http://cyberduck.ch/
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // Bug fixes, suggestions and comments should be sent to:
16 // yves@cyberduck.ch
17 //
19 using System;
20 using ch.cyberduck.core;
21 using ch.cyberduck.core.preferences;
22 using org.apache.log4j;
24 namespace Ch.Cyberduck.Core
26 public class DataProtectorPasswordStore : HostPasswordStore
28 private static readonly Logger Log = Logger.getLogger(typeof (Keychain).FullName);
30 public override string getPassword(Scheme scheme, int port, String hostName, String user)
32 Host host = new Host(ProtocolFactory.forScheme(scheme.name()), hostName, port);
33 host.getCredentials().setUsername(user);
34 return getPassword(host);
37 public override string getPassword(String hostName, String user)
39 Host host = new Host(hostName);
40 host.getCredentials().setUsername(user);
41 return getPassword(host);
44 public override void addPassword(String hostName, String user, String password)
46 Host host = new Host(hostName);
47 host.getCredentials().setUsername(user);
48 PreferencesFactory.get().setProperty(new HostUrlProvider().get(host), DataProtector.Encrypt(password));
51 public override void addPassword(Scheme scheme, int port, String hostName, String user, String password)
53 Host host = new Host(ProtocolFactory.forScheme(scheme.name()), hostName, port);
54 host.getCredentials().setUsername(user);
55 PreferencesFactory.get().setProperty(new HostUrlProvider().get(host), DataProtector.Encrypt(password));
58 private string getPassword(Host host)
60 string password = PreferencesFactory.get().getProperty(new HostUrlProvider().get(host));
61 if (null == password)
63 return null;
65 return DataProtector.Decrypt(password);