The following problem is happening. Our company is changing all the passwords of the users.
They asked me to write a program so that the user can enter his or her's username and new password so this will be replaced in the windows credentials manager. (Windows Vault).
What I am trying to do is to get all the stored credentials in the credential manager with a specified username. When I find the username I will edit the password.
I do not know the Target name so I cannot find the credentials with a Target name.
I made the following script with https://www.nuget.org/packages/CredentialManagement/:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CredentialManagement;
using System.Diagnostics;
using System.Security;
using Microsoft.Win32.SafeHandles;
namespace RU_PWReplacer
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetCredentials();
}
public void GetCredentials()
{
List<Credential> Credentials = new List<Credential>();
List<string> TargetPath = new List<string>();
TargetPath.Add("test1.nl");
TargetPath.Add("test2.nl");
TargetPath.Add("test3.nl");
for (int i = 0; i < TargetPath.Count; i++)
{
Credential Try_ToFind_Credential = new Credential { Target = TargetPath[i], Type = CredentialType.DomainPassword };
Credentials.Add(Try_ToFind_Credential);
}
foreach (Credential c in Credentials)
{
if (!c.Exists())
{
Console.Write("Not Found\n");
}
else
{
Console.Write("Found\n");
}
}
}
}
}
The problem is that this way I am searching with a Target name and that is not a possibility, because there can be a lot of target names. So searching for a Username is more efficient.
If have found this post: How do I store and retrieve credentials from the Windows Vault credential manager?
The problem with this is that it still uses a Target name to find the credential.
I hope you guys can point me in the right direction.
With kind regards,
Dennis.
Related
The following works great on my local IIS and return videos. When I run it on my GoDaddy shared hosting website (using https), it returns "This page can't be displayed". My code is below and I have isolated the problem down to this statement:
// Execute search
SearchListResponse searchListResponse = searchListRequest.Execute();
I have searched but cannot find solution and even called GoDaddy for help but no joy yet. Hope someone can help resolve.
Here's the source code snippet:
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
//using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
public void runSearch(string query)
{
try
{
// Create YouTube Service
YouTubeService youTubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "xxxx",
ApplicationName = this.GetType().ToString()
});
SearchResource.ListRequest searchListRequest = youTubeService.Search.List("snippet");
searchListRequest.Q = query;
searchListRequest.MaxResults = 15;
searchListRequest.Type = "video";
// Execute search
SearchListResponse searchListResponse = searchListRequest.Execute();
...
}
This code is changing fast and hard to get a handle on what works and what doesn't...
I was looking at this post: Have you used Google's Directory API?
Which is using the 1.4 library.
I installed the 1.6 API through nuget. However, the NativeApplicationClient and IAuthorizationState cannot be resolved. I was under the impression that I no longer needed the DotNetOpenAuth nuget package or the Google.Apis.Authentication package (which is where I believe they are resolved.
This is the complete and modified code I am playing with: (if you have a better example of creating users using the new API I'd like to see that!)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth;
using Google.Apis.Download;
using Google.Apis.Logging;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Admin.Directory;
using Google.Apis.Admin.Directory.directory_v1.Data;
namespace GoogleAddUser
{
class Program
{
static void Main(string[] args)
{
// Display the header and initialize the sample.
//CommandLine.EnableExceptionHandling();
Console.WriteLine("Create users in a google apps domain!");
Console.WriteLine("by Jonas Bergstedt 2013");
// Get the user data and store in user object
Console.Write("Email: ");
string userId = Console.ReadLine();
Console.Write("Givenname: ");
string GivenName = Console.ReadLine();
Console.Write("Familyname: ");
string FamilyName = Console.ReadLine();
Console.Write("Password: ");
string Password = Console.ReadLine();
User newuserbody = new User();
UserName newusername = new UserName();
newuserbody.PrimaryEmail = userId;
newusername.GivenName = GivenName;
newusername.FamilyName = FamilyName;
newuserbody.Name = newusername;
newuserbody.Password = Password;
// Register the authenticator.
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier = "<your clientId from Google APIs Console>",
ClientSecret = "<your clientsecret from Google APIs Console>",
};
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
// Create the service.
var service = new DirectoryService(new BaseClientService.Initializer()
{
Authenticator = auth,
ApplicationName = "Create User",
ApiKey = "<your API Key from Google APIs console> (not sure if needed)"
});
User results = service.Users.Insert(newuserbody).Execute();
Console.WriteLine("User :" + results.PrimaryEmail + " is created");
Console.WriteLine("Press any key to continue!");
Console.ReadKey();
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { DirectoryService.Scopes.AdminDirectoryUser.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.WriteLine();
Console.Write("Authorization Code: ");
string authCode = Console.ReadLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
From release 1.6.0-beta we presented a new Google.Apis.Auth NuGet package (Google.Apis.Authentication which uses DNOA is obsolete!). You already installed that package, because all the new APIs have a reference to it. Take a look in our OAuth2 wiki page for more details about how to use the new OAuth2 flows (it's not magic anymore, now the flows actually make sense!)
I recommend you subscribing to our announcement blog and optionally to my personal blog to get more information about the client library. In our announcement blog we described the reason the new OAuth2 pacakge.
Hope it is helpful.
I am making a simple app that sends location data to a server using http get request.
The problem is that the request is made only on the first time despite the fact that it is inside the positionchanged event handler.
Here is my code. I can't find what is wrong with it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;
namespace kechap
{
public partial class MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher gw = new GeoCoordinateWatcher();
Uri url = new Uri("http://127.0.0.1:5000/upload/1e3fae069dd62fa1641183cd77092ed2053a0e75/1/2");
// Constructor
public MainPage()
{
InitializeComponent();
gw.MovementThreshold = 10;
gw.PositionChanged += (s, e) =>
{
MyMap.Center = e.Position.Location;
MyPushpin.Location = e.Position.Location;
WebClient wc = new WebClient();
wc.OpenReadAsync(url);
wc.OpenReadCompleted += (ss, ee) =>
{
};
};
gw.Start();
}
}
}
At a guess I would say the URI, which in the code you have posted does not change between calls, is resolved from cache after the first time. I suggest you use the age old hack of appending a parameter and giving it a value that changes with each invocation (eg the position you seem to want to report).
I used visual2010 to write a simple app with httpWebRequest class. The very first time of running the app, it'd work but after some successes, it was stuck with warning
"unable to connect the remote server".
I have read a lot in net but not much clues could done, almost said because the anti virus soft or firewall cause the problem, but when i'd turn off both, it still does not work. I also reinstall visual2010 but the problem still
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace new_httpWebRequest
{
class Program
{
static void Main(string[] args)
{
string result ="";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://my-favor.net");
// line code problem below:
`HttpWebResponse response = (HttpWebResponse)request.GetResponse();`
var sr = new StreamReader(response.GetResponseStream() ?? System.IO.Stream.Null, Encoding.UTF8);
result = sr.ReadToEnd();
sr.Close();
Console.Write(result);
Console.ReadLine();
}
}
}
finally, i find the solution just by adding this line:
request.Proxy = null;
I don't know why it work, just do it by god bless.
I wrote one program which sends request for particular site and gets response. It properly runs with localhost. but, if i put www.google.com then it prompts error as "The remore sever returned an error: Not Found"
****Code*****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
namespace WindowsPhoneApplication2
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
var request = (HttpWebRequest)WebRequest.Create(new Uri(#"http://www.google.com"));
request.BeginGetResponse(r =>
{
var httpRequest = (HttpWebRequest)r.AsyncState;
var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
using (var reader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = reader.ReadToEnd();
Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { textBox1.Text = response; }));
}
}, request);
}
}
}
please tell me soultion
thanx in advance
Your code works for me.
Can you access Google from IE on the device/emulator?
I suspect that this is a networking issue local to you and not related to the device.