当前位置: 首页>>代码示例>>C#>>正文


C# Credentials.getUsername方法代码示例

本文整理汇总了C#中Credentials.getUsername方法的典型用法代码示例。如果您正苦于以下问题:C# Credentials.getUsername方法的具体用法?C# Credentials.getUsername怎么用?C# Credentials.getUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Credentials的用法示例。


在下文中一共展示了Credentials.getUsername方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: changePassword

    public static bool changePassword(Credentials user)
    {
        String database = System.Configuration.ConfigurationManager.ConnectionStrings["programaholics_anonymous_databaseConnectionString"].ConnectionString;
        using (OleDbConnection sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + database))
        {
            try
            {
                sqlConn.Open();

                OleDbCommand cmd = sqlConn.CreateCommand();
                OleDbTransaction transact = sqlConn.BeginTransaction(); //using a transaction incase something goes wrong...
                cmd.Transaction = transact;

                String update = "UPDATE [password] INNER JOIN [users] ON [users].password = [password].ID SET [password].[password] = @password, [password].[salt] = @salt WHERE [users].username = @username";
                cmd.CommandText = update;
                cmd.Parameters.Add("password", OleDbType.VarChar, 255).Value = user.getPassword();
                cmd.Parameters.Add("salt", OleDbType.VarChar, 255).Value = user.getSalt();
                cmd.Parameters.Add("username", OleDbType.VarChar, 255).Value = user.getUsername();

                int rows = cmd.ExecuteNonQuery();

                if (rows == 1)
                {
                    transact.Commit();
                    return true;
                }
                else
                {
                    return false;
                }
            }

            catch (OleDbException ex)
            {
                return false;
            }
            finally
            {
                sqlConn.Close();
            }

        }
    }
开发者ID:craig-smith,项目名称:CISSeniorProjectTest,代码行数:43,代码来源:UserDao.cs

示例2: createAccount

    //This method adds a new username password combination to the database
    public static bool createAccount(Credentials newUser)
    {
        Boolean created;
        String database = System.Configuration.ConfigurationManager.ConnectionStrings["programaholics_anonymous_databaseConnectionString"].ConnectionString;
        using (OleDbConnection sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + database))
        {
            try
            {
                sqlConn.Open();

                OleDbCommand cmd = sqlConn.CreateCommand();
                OleDbTransaction transact = sqlConn.BeginTransaction(); //useing a transaction because we need to update 2 tables in db
                cmd.Transaction = transact;

                String insert2 = "INSERT INTO [password]([password], [salt]) VALUES (@password, @salt)";
                cmd.Parameters.Clear();
                cmd.CommandText = insert2;
                cmd.Parameters.Add("password", OleDbType.VarChar, 255).Value = newUser.getPassword();
                cmd.Parameters.Add("salt", OleDbType.VarChar, 255).Value = newUser.getSalt();
                cmd.Prepare();

                int rows1 = cmd.ExecuteNonQuery();

                String select = "SELECT LAST(ID) FROM [password]";
                cmd.Parameters.Clear();
                cmd.CommandText = select;
                cmd.Prepare();

                int ID = 0;
                OleDbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ID = Convert.ToInt32(reader[ID]);
                }
                reader.Close();

                String insert = "INSERT INTO [users]([username], [accessLevel], [password], [createdOnDate]) VALUES (@username, 2, @password, @date)";
                cmd.CommandText = insert;
                cmd.Parameters.Add("username", OleDbType.VarChar, 255).Value = newUser.getUsername();
                cmd.Parameters.Add("password", OleDbType.Integer, 32).Value = ID;
                cmd.Parameters.Add("date", OleDbType.Date).Value = System.DateTime.Now;
                cmd.Prepare();

                int rows2 = cmd.ExecuteNonQuery();

                //check if all parts of transaction were successful
                if (rows1 == 1 && rows2 == 1)
                {
                    transact.Commit();
                    created = true;
                }
                else
                {
                    transact.Rollback(); //cancel transaction if unsuccessful
                    created = false;
                }
            }

            catch (OleDbException ex)
            {
                return false;
            }
            finally
            {
                sqlConn.Close();

            }
            return created;
        }
    }
开发者ID:craig-smith,项目名称:CISSeniorProjectTest,代码行数:71,代码来源:UserDao.cs

示例3: prompt

        public override void prompt(Protocol protocol, Credentials credentials,
            String title, String reason,
            bool enableKeychain, bool enablePublicKey, bool enableAnonymous)
        {
            _view = ObjectFactory.GetInstance<ILoginView>();
            InitEventHandlers();

            _protocol = protocol;
            _credentials = credentials;
            _enableKeychain = enableKeychain;
            _enablePublicKey = enablePublicKey;//
            _enableAnonymous = enableAnonymous;

            _view.Title = Locale.localizedString(title, "Credentials");
            _view.Message = Locale.localizedString(reason, "Credentials");
            _view.Username = credentials.getUsername();
            _view.UsernameLabel = protocol.getUsernamePlaceholder() + ":";
            _view.PasswordLabel = protocol.getPasswordPlaceholder() + ":";
            _view.SavePasswordState =
                Preferences.instance().getBoolean("connection.login.useKeychain") &&
                Preferences.instance().getBoolean("connection.login.addKeychain");
            _view.DiskIcon = IconCache.Instance.IconForName(_protocol.disk(), 64);

            Update();

            AsyncController.AsyncDelegate d = delegate
            {
                if (DialogResult.Cancel == _view.ShowDialog(_browser.View))
                {
                    throw new LoginCanceledException();
                }
                credentials.setSaved(_view.SavePasswordState);
                credentials.setUsername(Utils.SafeString(_view.Username));
                credentials.setPassword(Utils.SafeString(_view.Password));
            };
            _browser.Invoke(d);
        }
开发者ID:kaduardo,项目名称:cyberduck,代码行数:37,代码来源:LoginController.cs


注:本文中的Credentials.getUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。