- Enter the following command: sudo passwd root
- You will be prompted to enter your new password twice
- Enter su root and your new password
DONE! Very short and to the point!
Knowledge is power...Share the knowledge and increase the power for everyone.
Today I released Stock Purchase Calculator v1.0.0 to Google Play. The application provides a way to quickly get an idea of how many stocks you can buy with a certain amount of money and how much you could make if you sold the stock at a certain price?
The application provides the total purchase and total sell amounts for a given number of stock shares minus broker commissions. In addition both net profit and loss, net change, and the stock symbol for a given company are reported.
The following is a direct link to the application on Google Play:
protected void NewUserWizard_CreatingUser(object sender, LoginCancelEventArgs e)
{
Label invalidFile = (Label)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ErrorLabel");
FileUpload userImage = (FileUpload)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserImageFileUpload");
// Check whether we have a file to save or not.
if (userImage.HasFile)
{
// Check that the file type is supported.
string fileExtension = Path.GetExtension(userImage.PostedFile.FileName);
switch (fileExtension)
{
case ".gif":
break;
case ".jpg":
case ".jpeg":
break;
case ".png":
break;
default:
invalidFile.Visible = true;
invalidFile.Text = "Supported file types are GIF, JPG, PNG.";
e.Cancel = true;
break;
}
}
}
private void DisplayUserImage()
{
if (Session["UserName"] != null)
{
MembershipUser user = Membership.GetUser(Session["UserName"].ToString());
Guid userGuid = (Guid)user.ProviderUserKey;
UserImage.ImageUrl = "Image.ashx?userGuid=" + userGuid;
}
}
public void ProcessRequest (HttpContext context)
{
string userGuid = string.Empty;
// Check that the querystring value is not null.
if (context.Request.QueryString["userGuid"] != null)
{
userGuid = context.Request.QueryString["userGuid"];
}
else
{
throw new ArgumentException("Missing user id.");
}
context.Response.ContentType = "image/jpeg";
// Pass the user's guid in, so that we can get the image associated with the logged in user.
Stream strm = GetImage(userGuid);
byte[] buffer = new byte[2048];
int byteSeq = strm.Read(buffer, 0, 2048);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 2048);
}
}
public Stream GetImage(string id)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
{
try
{
using (SqlCommand cmd = new SqlCommand("GetUserImage", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserId", id);
conn.Open();
byte[] img = (byte[])cmd.ExecuteScalar();
try
{
return new MemoryStream(img);
}
catch
{
return null;
}
finally
{
conn.Close();
}
}
}
catch (SqlException sqlEx)
{
throw sqlEx;
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
We’ve all visited websites that provide a test or demo site and allow you to login for the purpose of testing features out using specific user accounts with assigned roles. If you have a website or web application that needs to provide this type of functionality, I’m going to show you how you can save the user a few keystrokes by filling in the Username and Password for them, so that all they have to do is click the Login button.
What I have done is created three accounts: Admin, User, and Guest along with a Default.aspx page which resides under the respective folder. The folder structure is as follows for these accounts:
Admin/Default.aspx
User/Default.aspx
Guest/Default.aspx
I’ve created a login page (Login.aspx) and dropped a Login Control on it. The Login Control has been converted to a template and I’ve added a label and dropdown list to it. The dropdown list contains the user accounts that will be selected for logging in.
Within the Load event of the Login Control I get a reference to the dropdown list and password textbox controls, so that they can be used in selecting the proper user and populating the password textbox. I add an attribute to the password textbox, which sets the password, so that the user does not have to type it in. Something to be mindful of is that the password is viewable in plain text if you view the pages source. Because these accounts are being used to save the user a few of keystrokes for a test or demo site login this isn’t much of an issue.
DropDownList userLogin = (DropDownList)DemoLogin.FindControl("UserDropDownList");TextBox passwd = (TextBox)DemoLogin.FindControl("Password");switch (userLogin.SelectedValue){case "Admin":DemoLogin.UserName = userLogin.SelectedValue;passwd.Attributes.Add("value", "Adm!n123");break;case "User":DemoLogin.UserName = userLogin.SelectedValue;passwd.Attributes.Add("value", "U$er123");break;case "Guest":DemoLogin.UserName = userLogin.SelectedValue;passwd.Attributes.Add("value", "Gue$t123");break;default:DemoLogin.UserName = string.Empty;passwd.Attributes.Add("value", "");break;}
The only other thing needed is within the Login Control’s LoggedIn event to check the role of the user and then redirect them to the appropriate Default.aspx page.
if (Roles.IsUserInRole(DemoLogin.UserName, "Admin")){Response.Redirect("~/Admin/Default.aspx");}else if (Roles.IsUserInRole(DemoLogin.UserName, "User")){Response.Redirect("~/User/Default.aspx");}else if (Roles.IsUserInRole(DemoLogin.UserName, "Guest")){Response.Redirect("~/Guest/Default.aspx");}else{Response.Redirect("~/Login.aspx");}
While this is pretty trivial, it does save a few keystrokes by allowing the user to just select the user account they wish to login as and then all they have to do is click the login button.
<add name="AspNetSqlMembershipProvider" connectionStringName="MyAspNetDB" applicationName="/"passwordFormat="Hashed"passwordAttemptWindow="30"minRequiredNonalphanumericCharacters="1"minRequiredPasswordLength="7"maxInvalidPasswordAttempts="3"type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
public int failedLoginCount;protected void Page_Init(object sender, EventArgs e){ViewState.Add("FailedLoginCount", failedLoginCount + 1);}protected void Page_Load(object sender, EventArgs e){failedLoginCount = (int) ViewState["FailedLoginCount"];}
protected void Login1_LoggedIn(object sender, EventArgs e){Login logIn = (Login) LoginView1.FindControl("Login1");if (Roles.IsUserInRole(logIn.UserName, "Administrators")){Response.Redirect("~/Admin/Admin.aspx");}else{Response.Redirect("~/Standard/Standard.aspx");}}
protected void Login1_LoginError(object sender, EventArgs e){string emailLink = "<a href=mailto:admin@somesite.com>";emailLink += "Site Administrator";emailLink += "</a>";Login logIn = (Login)LoginView1.FindControl("Login1");if (failedLoginCount == 3){logIn.FailureText = "Your account has been disabled. Please contact the site administrator: " + emailLink;MembershipUser user = Membership.GetUser(logIn.UserName);user.IsApproved = false;}else{logIn.FailureText = "Failed login attempt [" + ViewState["FailedLoginCount"].ToString() + "]";failedLoginCount++;ViewState.Add("FailedLoginCount", failedLoginCount);}}
SELECT UserName, Email, LastLockoutDate, IsLockedOutFROM vw_aspnet_MembershipUsersWHERE IsLockedOut = 1
protected void Page_Load(object sender, EventArgs e){if (!Page.IsPostBack)
{LockedUsersGridView.DataSource = GetLockedUsers();LockedUsersGridView.DataBind();}}private DataTable GetLockedUsers()
{DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyAspNetDB"].ConnectionString)){using (SqlCommand cmd = new SqlCommand("SELECT UserName, Email, LastLockoutDate, IsLockedOut FROM vw_aspnet_MembershipUsers WHERE IsLockedOut = 1", conn)){cmd.CommandType = CommandType.Text;try
{conn.Open();da.SelectCommand = cmd;da.Fill(dt);if (dt.Rows == null || dt.Rows.Count < 1){LockedUsersLabel.Text = string.Empty;
return dt;
}cmd.ExecuteNonQuery();}catch (SqlException sqlEx)
{LockedUsersGridView.Rows[0].Cells[0].Text = sqlEx.ToString();}}}return dt;
}protected void LockedUsersGridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e){LockedUsersGridView.PageIndex = e.NewSelectedIndex;LockedUsersGridView.DataSource = GetLockedUsers();LockedUsersGridView.DataBind();}protected void LockedUsersGridView_RowEditing(object sender, GridViewEditEventArgs e){LockedUsersGridView.EditIndex = e.NewEditIndex;LockedUsersGridView.DataSource = GetLockedUsers();LockedUsersGridView.DataBind();}protected void LockedUsersGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e){LockedUsersGridView.EditIndex = -1;LockedUsersGridView.DataSource = GetLockedUsers();LockedUsersGridView.DataBind();}protected void LockedUsersGridView_RowUpdating(object sender, GridViewUpdateEventArgs e){TextBox userName = LockedUsersGridView.Rows[e.RowIndex].FindControl("UserNameTextBox") as TextBox;if (userName != null){MembershipUser user = Membership.GetUser(userName.Text.Trim());user.UnlockUser();Membership.UpdateUser(user);}LockedUsersGridView.EditIndex = -1;LockedUsersGridView.DataSource = GetLockedUsers();LockedUsersGridView.DataBind();}protected void LockedUsersGridView_PageIndexChanging(object sender, GridViewPageEventArgs e){LockedUsersGridView.PageIndex = e.NewPageIndex;LockedUsersGridView.DataSource = GetLockedUsers();LockedUsersGridView.DataBind();}
I just thought I’d take a moment and share the experience I had with Optimized Cable Company. I was searching for a set of HDMI-DVI and DVI-DVI cables for two monitors and decided to try the products of Optimized Cable Company. I found their selection of cables to be of high quality and their prices to be competitive. What prompted me; however, to write about this was the excellent customer service they provided. So often we are quick to post and talk about our bad experiences and rarely do we share the positive experiences we have with companies.
The positive experience I had with Optimized Cable Company is one of those great experiences you rarely hear about. When I ordered my set of cables, which were delivered very quickly (I might add), I realized I had not paid close enough attention to the connectors. One of my monitors had an HDMI connector, while the other had DVI; however, both of my video cards had DVI connectors. When I realized my ordering error I promptly called them and explained my mistake and they said to just send them back the incorrect cable and they would promptly send me the correct cable, which was slightly more expensive than the one I originally ordered. They did an even exchange and I received the cable I intended to purchase at no additional cost to me or hassle.
Based on the quality of the cables I received, prompt delivery, and the ease of doing business with them. I will direct my future needs for cables to them and highly recommend them for all of your cable needs.
Thank you Optimized Cable Company!
Optimized Cable Company