本文整理汇总了C#中Credential类的典型用法代码示例。如果您正苦于以下问题:C# Credential类的具体用法?C# Credential怎么用?C# Credential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credential类属于命名空间,在下文中一共展示了Credential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAssetsAsync
public async Task<IEnumerable<Asset>> GetAssetsAsync(Credential credentials)
{
if (!(await AccessAllowed(credentials.AccessMask, CallEndPoint.AssetList)))
throw new UnauthorizedAccessException();
return await _repo.GetAssetsAsync(1, credentials);
}
示例2: EncryptCredentialBasedOnCertificateOfServer
/// <summary>
/// Encrypt credential based on the public key of server
/// </summary>
/// <param name="credential"></param>
/// <param name="certificate"></param>
/// <returns></returns>
public byte[] EncryptCredentialBasedOnCertificateOfServer(Credential credential,X509Certificate2 certificate)
{
RSACryptoServiceProvider publicKey = (RSACryptoServiceProvider)certificate.PublicKey.Key;
string info = JsonConvert.SerializeObject(credential);
byte[] credentialInfoByte = publicKey.Encrypt(System.Text.Encoding.Default.GetBytes(info), false);
return credentialInfoByte;
}
示例3: AddRange
public void AddRange(Credential.Info[] cInfo)
{
foreach (Credential.Info cI in cInfo)
{
List.Add(cI);
}
}
示例4: AddDomainUserCredential
/// <summary>
/// Adds the domain user credential.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="userName">Name of the user.</param>
/// <param name="password">The password.</param>
public static void AddDomainUserCredential(string target, string userName, string password)
{
Credential userCredential = new Credential();
try
{
userCredential.TargetName = target;
userCredential.Type = (uint)CRED_TYPE.CRED_TYPE_DOMAIN_PASSWORD;
userCredential.UserName = userName;
userCredential.AttributeCount = 0;
userCredential.Persist = (uint)CRED_PERSIST.CRED_PERSIST_LOCAL_MACHINE;
byte[] bpassword = Encoding.Unicode.GetBytes(password);
userCredential.CredentialBlobSize = (uint)bpassword.Length;
userCredential.CredentialBlob = Marshal.StringToCoTaskMemUni(password);
if (!CredWrite(ref userCredential, (uint)0))
{
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
}
}
finally
{
if (userCredential.CredentialBlob != null)
{
Marshal.FreeCoTaskMem(userCredential.CredentialBlob);
}
}
}
示例5: GetIndustryJobsAsync
public async Task<IEnumerable<IndustryJob>> GetIndustryJobsAsync(Credential credentials)
{
if (!(await AccessAllowed(credentials.AccessMask, CallEndPoint.IndustryJobs)))
throw new UnauthorizedAccessException();
return await _repo.GetIndustryJobsAsync(1, credentials);
}
示例6: UserAuthenticated
private void UserAuthenticated(Credential credential)
{
if (credential != null)
{
DialogResult = true;
}
}
示例7: GetTransactionsAsync
public async Task<IEnumerable<Transaction>> GetTransactionsAsync(Credential credentials)
{
if (!(await AccessAllowed(credentials.AccessMask, CallEndPoint.WalletTransactions)))
throw new UnauthorizedAccessException();
throw new NotImplementedException();
}
示例8: PutCredential
public IHttpActionResult PutCredential(int id, Credential credential)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != credential.ID)
{
return BadRequest();
}
db.Entry(credential).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!CredentialExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
示例9: Create
public ActionResult Create(CredentialCreateModel model)
{
if (ModelState.IsValid)
{
try
{
using (var db = new MySelfieEntities())
{
var entity = new Credential();
entity.MergeWithOtherType(model);
db.Credentials.Add(entity);
db.SaveChanges();
}
}
catch (Exception ex)
{
ModelState.AddModelError("ex", ex);
return View(model);
}
return RedirectToRoute("credential_index_g");
}
return View(model);
}
示例10: ValidateCredentials
public bool ValidateCredentials(ICollection<Credential> credentials, string password, out Credential matched)
{
var ldapCred = credentials.FirstOrDefault(c => c.Type == CredentialType_LdapUser);
matched = ldapCred;
if (ldapCred != null)
{
try
{
LdapConnection connection = new LdapConnection(this.Configuration.Server);
connection.SessionOptions.SecureSocketLayer = true;
connection.SessionOptions.VerifyServerCertificate = (ldapConnection, certificate) =>
{
return true;
};
connection.AuthType = AuthType.Negotiate;
NetworkCredential credential = new NetworkCredential(ldapCred.Value, password);
connection.Credential = credential;
connection.Bind();
return true;
}
catch (Exception)
{
return false;
}
}
return false;
}
示例11: CheckPayooAccount
public String CheckPayooAccount(String username)
{
String result = "";
try
{
Credential credential = new Credential();
credential.APIUsername = ConfigurationManager.AppSettings["APIUsername"];
credential.APIPassword = ConfigurationManager.AppSettings["APIPassword"];
credential.APISignature = ConfigurationManager.AppSettings["APISignature"];
Caller caller = new Caller();
caller.InitCall(ConfigurationManager.AppSettings["PayooBusinessAPI"], credential,
Server.MapPath(@"..\App_Data\Certificates\biz_pkcs12.p12"), "alpe", Server.MapPath(@"..\App_Data\Certificates\payoo_public_cert.pem"));
CheckPayooAccountRequestType req = new CheckPayooAccountRequestType();
req.AccountID = username; // agentb2 ; vimp71 | [email protected]
CheckPayooAccountResponseType res = (CheckPayooAccountResponseType)caller.Call("CheckPayooAccount", req);
if (res.Ack == AckCodeType.Success)
{
result = "Valid";
}
else
{
result = "InValid Account";
}
}
catch (Exception ex)
{
result = "False";
throw ex;
}
return result;
}
示例12: AuthenticateAsync
public async Task<ICredential> AuthenticateAsync(Uri requestUri, Uri callbackUri = null)
{
var requestUriStrb = new StringBuilder();
requestUriStrb.Append(requestUri.AbsoluteUri);
if (callbackUri != null)
{
requestUriStrb.AppendFormat("&oauth_callback={0}", callbackUri.AbsoluteUri);
}
var listener = new HttpListener();
listener.Prefixes.Add(callbackUri.AbsoluteUri);
listener.Start();
System.Diagnostics.Process.Start(requestUriStrb.ToString());
var ctx = await listener.GetContextAsync();
var token = new Credential(ctx.Request.QueryString.Get("oauth_token"), ctx.Request.QueryString.Get("oauth_verifier"));
// empty response
// ctx.Response.ContentLength64 = 0;
// await ctx.Response.OutputStream.WriteAsync(new byte[0], 0, 0);
ctx.Response.OutputStream.Close();
listener.Stop();
return token;
}
示例13: AddCredential
/// <summary>
/// Adds a credential to the credential locker.
/// </summary>
/// <param name="credential">The credential to be added.</param>
public static void AddCredential(Credential credential)
{
if (credential == null || string.IsNullOrEmpty(credential.ServiceUri))
return;
var serverInfo = IdentityManager.Current.FindServerInfo(credential.ServiceUri);
var host = serverInfo == null ? credential.ServiceUri : serverInfo.ServerUri;
string passwordValue = null; // value stored as password in the password locker
string userName = null;
var oAuthTokenCredential = credential as OAuthTokenCredential;
var arcGISTokenCredential = credential as ArcGISTokenCredential;
var arcGISNetworkCredential = credential as ArcGISNetworkCredential;
if (oAuthTokenCredential != null)
{
userName = oAuthTokenCredential.UserName;
if (!string.IsNullOrEmpty(oAuthTokenCredential.OAuthRefreshToken)) // refreshable OAuth token --> we store it so we'll be able to generate a new token from it
passwordValue = OAuthRefreshTokenPrefix + oAuthTokenCredential.OAuthRefreshToken;
else if (!string.IsNullOrEmpty(oAuthTokenCredential.Token))
passwordValue = OAuthAccessTokenPrefix + oAuthTokenCredential.Token;
}
else if (arcGISTokenCredential != null)
{
userName = arcGISTokenCredential.UserName;
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(arcGISTokenCredential.Password)) // Token generated from an username/password --> store the password
passwordValue = PasswordPrefix + arcGISTokenCredential.Password;
}
else if (arcGISNetworkCredential != null)
{
// networkcredential: store the password
if (arcGISNetworkCredential.Credentials != null)
{
NetworkCredential networkCredential = arcGISNetworkCredential.Credentials.GetCredential(new Uri(host), "");
if (networkCredential != null && !string.IsNullOrEmpty(networkCredential.Password))
{
userName = networkCredential.UserName;
if (!string.IsNullOrEmpty(networkCredential.Domain))
userName = networkCredential.Domain + "\\" + userName;
passwordValue = NetworkCredentialPasswordPrefix + networkCredential.Password;
}
}
}
// Store the value in the password locker
if (passwordValue != null)
{
var passwordVault = new PasswordVault();
var resource = ResourcePrefix + host;
// remove previous resource stored for the same host
try // FindAllByResource throws an exception when no pc are stored
{
foreach (PasswordCredential pc in passwordVault.FindAllByResource(resource))
passwordVault.Remove(pc);
}
catch {}
passwordVault.Add(new PasswordCredential(resource, userName, passwordValue));
}
}
示例14: UpdateDialog
public UpdateDialog(string fileName, Credential cred)
{
InitializeComponent();
FileName = fileName;
InitializeUI(cred);
}
示例15: AddCredentialToCustomer
public void AddCredentialToCustomer(Credential credential, int customerID)
{
var customer = Customers.Where(c => c.ID == customerID).First();
credential.CustomerID = customer.ID;
credential.MyCustomer = customer;
customer.Credentials.Add(credential);
}