I'm using the asp.net Membership Provider in an application.
I'm also using the "out of the box" asp:PasswordRecovery control.
My client is complaining that the new passwords being issued are too complicated.
e.g. }>;-(hYrS^OTfY
Are there any small tweaks I can make so the new passwords only contain letters and numbers?
thanks!
This worked:
using System;
using System.Collections.Generic;
using System.Web.Profile;
using System.Web.Security;
using System.Text;
namespace TS.Common.MembershipProvider
{
public class MembershipProvider : SqlMembershipProvider
{
/// Create an array of characters to user for password reset.
/// Exclude confusing or ambiguous characters such as 1 0 l o i
string[] characters = new string[] { "2", "3", "4", "5", "6", "7", "8",
"9", "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
const int DefaultResetPasswordLength = 10;
private int ResetPasswordLength;
// Create a more user friendly password to avoid confusion when
// trying to key in the new value
public override string GeneratePassword()
{
string newPassword = string.Empty;
System.Random rnd = new Random();
for (int i = 0; i < ResetPasswordLength; i++)
{
newPassword +=
characters[rnd.Next(characters.GetUpperBound(0))];
}
return newPassword;
}
}
}
Related
input: "abcd"
output: a list of all the ways to cut off the string.
[ ["a", "bcd"],["a", "b", "cd"], ["a", "b", "c", "d"],
["ab", "cd"], ["ab", "c", "d"],
["abc", "d"],
["abcd", ""]
]
I want a recursive solution. Preferably Java but not need to be language specific.
Thank you!
Please notice "abd" "c" is not valid, because you cannot rearrange the order.
There are a lot of ways to solve this problem. Here is one of them
import java.util.ArrayList;
import java.util.List;
public class Splitter {
public static void main(String[] args) {
final String string = "abcd";
//You should add empty string as a base
printAllSplits(string, 0, new ArrayList<>(List.of(new StringBuilder())));
}
static void printAllSplits(String s, int currentIndex, List<StringBuilder> list) {
if (currentIndex == s.length()) { //reached the end, nothing left to split
System.out.println(list);
return;
}
//We should consider two decisions at each index: 1. split
// 2. don't split
//split here
if (currentIndex > 0) {
list.add(new StringBuilder(Character.toString(s.charAt(currentIndex))));
printAllSplits(s, currentIndex + 1, list);
//remove it not to affect a future call
list.remove(list.size() - 1);
}
//don't split here
list.get(list.size() - 1).append(s.charAt(currentIndex));
printAllSplits(s, currentIndex + 1, list);
}
}
You can modify this code to fit your needs. If you don't like or understand anything, feel free to ask. Also, if you need exactly a string, you can convert string builder to string at the end. I use string builder, because it's mutable.
I have a requirement to create a set of strings using an array of strings in Ballerina. Other than using reduce() or checking indexOf() before inserting, I couldn't find a way to create a set using Ballerina programming language.
string[] arr = ["a", "b", "c", "a", "d", "c"];
string[] set = arr.reduce(function(string[] accum, string item) returns string[] {
if accum.indexOf(item) == () {
accum.push(item);
}
return accum;
}, []);
Is there a better way to create a set in Ballerina?
Since what you want is just set of strings, I would suggest to use a map.
import ballerina/io;
public function main() {
string[] s = ["a", "b", "a"];
map<()> m = {};
foreach var i in s {
m[i] = ();
}
string[] unique = m.keys();
io:println(unique);
}
For set of complex type, we can go with a table and do something similar to what we did with map.
If the intended members of the set are not strings; we can use a table instead. Below is an example
import ballerina/io;
type TblConstraint record {|
//can use a type that is a subtype of anydata
readonly anydata keyValue;
|};
public function main() {
int[] arr = [1, 2, 3, 3, 4, 4, 5];
table<TblConstraint> key(keyValue) setImpl = table [];
foreach int item in arr {
if (!setImpl.hasKey(item)) {
setImpl.put({keyValue: item});
}
}
//unique values as in a set
io:println(setImpl.keys());
}
Is there a more ruby way to achieve this dynamically, perhaps recursively. Currently I have player's table with some attributes that I care about like SURNAME, GIVEN_NAME, AT_BATS, RUNS, HITS, HOME_RUNS, RBI, etc. How can I access the player's hash values and load it into my database dynamically? Currently I have the following which works, however I'm fetching the teams manually and iterating over the "all_players" array. There's got to be a simpler rubyish way. Please note I skipped the closing brackets in the Json example below for example purposes.
seeds.rb
file = File.read("#{Rails.root}/db/1998_stats.json")
data_hash = JSON.parse(file).with_indifferent_access
#####################ALL TEAMS ###################################
braves = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][0]['TEAM'][0]['PLAYER']
marlins = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][0]['TEAM'][1]['PLAYER']
expos = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][0]['TEAM'][2]['PLAYER']
mets = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][0]['TEAM'][3]['PLAYER']
phillies = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][0]['TEAM'][4]['PLAYER']
cubs = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][1]['TEAM'][0]['PLAYER']
reds = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][1]['TEAM'][1]['PLAYER']
astros = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][1]['TEAM'][2]['PLAYER']
brewers = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][1]['TEAM'][3]['PLAYER']
pirates = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][1]['TEAM'][4]['PLAYER']
cardinals = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][1]['TEAM'][5]['PLAYER']
diamondbacks = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][2]['TEAM'][0]['PLAYER']
rockies = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][2]['TEAM'][1]['PLAYER']
dodgers = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][2]['TEAM'][2]['PLAYER']
padres = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][2]['TEAM'][3]['PLAYER']
giants = data_hash['SEASON']['LEAGUE'][0]['DIVISION'][2]['TEAM'][4]['PLAYER']
orioles = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][0]['TEAM'][0]['PLAYER']
redsox = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][0]['TEAM'][1]['PLAYER']
yankees = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][0]['TEAM'][2]['PLAYER']
devil_rays = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][0]['TEAM'][3]['PLAYER']
blue_jays = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][0]['TEAM'][4]['PLAYER']
whitesox = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][1]['TEAM'][0]['PLAYER']
royals = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][1]['TEAM'][1]['PLAYER']
tigers = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][1]['TEAM'][2]['PLAYER']
indians = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][1]['TEAM'][3]['PLAYER']
twins = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][1]['TEAM'][4]['PLAYER']
angels = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][2]['TEAM'][0]['PLAYER']
athletics = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][2]['TEAM'][1]['PLAYER']
mariners = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][2]['TEAM'][2]['PLAYER']
rangers = data_hash['SEASON']['LEAGUE'][1]['DIVISION'][2]['TEAM'][3]['PLAYER']
all_players = [braves, marlins, expos, mets, phillies, cubs, reds, astros, brewers, pirates, cardinals,
diamondbacks, rockies, dodgers, padres, giants, orioles, redsox, yankees, devil_rays, blue_jays,
whitesox, royals, tigers, indians, twins, angels, athletics, mariners, rangers]
all_players.each do |players_per_team|
players_per_team.each do |player|
Player.create! do |new_player|
new_player.first = player['GIVEN_NAME']
new_player.last = player['SURNAME']
new_player.position = player['POSITION']
new_player.hits = player['HITS']
new_player.bats = player['AT_BATS']
new_player.doubles = player['DOUBLES']
new_player.triples = player['TRIPLES']
new_player.walks = player['WALKS']
new_player.hbp = player['HIT_BY_PITCH']
new_player.sh = player['SACRIFICE_HITS']
new_player.sf = player['SACRIFICE_FLIES']
new_player.avg = nil
new_player.hr = player['HOME_RUNS']
new_player.rbi = player['RBI']
new_player.sb = player['STEALS']
new_player.ops = player['']
new_player.runs = player['']
new_player.obp = player['']
end
end
end
Json
{
"SEASON": {
"YEAR": "1998",
"LEAGUE": [
{
"LEAGUE_NAME": "National League",
"DIVISION": [
{
"DIVISION_NAME": "East",
"TEAM": [
{
"TEAM_CITY": "Atlanta",
"TEAM_NAME": "Braves",
"PLAYER": [
{
"SURNAME": "Malloy",
"GIVEN_NAME": "Marty",
"POSITION": "Second Base",
"GAMES": "11",
"GAMES_STARTED": "8",
"AT_BATS": "28",
"RUNS": "3",
"HITS": "5",
"DOUBLES": "1",
"TRIPLES": "0",
"HOME_RUNS": "1",
"RBI": "1",
"STEALS": "0",
"CAUGHT_STEALING": "0",
"SACRIFICE_HITS": "0",
"SACRIFICE_FLIES": "0",
"ERRORS": "0",
"PB": "0",
"WALKS": "2",
"STRUCK_OUT": "2",
"HIT_BY_PITCH": "0"
},
...
Recursion is not needed here.
# data_hash['SEASON']['LEAGUE'][1]['DIVISION'][0]['TEAM'][0]['PLAYER']
players = (0..1).map do |league|
(0..3).map do |division|
(0..40).map do |team|
data_hash['SEASON']['LEAGUE'][league]['DIVISION'][division]['TEAM'][team]['PLAYER']
end
end
end.flatten
The code is untested, but it should work.
public ActionResult BusinessUnitNameSelect(BusinessUnitDTO business)
{
BOSetup setup = new BOSetup();
string newBusiness = setup.BusinessUnitNameSelect(business);
return Json(newBusiness, JsonRequestBehavior.AllowGet);
}
Json returning string in this format. any solution to get string from json in actual format? Actual format is
General
{0: "G", 1: "e", 2: "n", 3: "e", 4: "r", 5: "a", 6: "l", $promise: Promise, $resolved: true}
I am trying to execute query through MVC3 with predicate builder. I am getting the error
"Unable to cast the type 'System.Boolean' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types."
I have query passed as below
if (!string.IsNullOrEmpty(SearchObj.EmployeeIDSortId.ToString()) && SearchObj.EmployeeIDSortId > 0)
{
string[] vals =new string[' '];
if (SearchObj.EmployeeIDSortId == 1)
{
vals = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k","l" };
}
else if (SearchObj.EmployeeIDSortId == 2)
{
vals = new string[] { "m", "n", "o", "p", "q", "r", "s" };
}
else if (SearchObj.EmployeeIDSortId == 3)
{
vals = new string[] { "t", "u", "v", "w", "x", "y", "z" };
}
employeepredicate =
employeepredicate.And(emp => emp.EmployeeName.Substring(0, 1).ToLower().Equals(vals.Any()));
}
Can you please suggest what is wrong with this ,I guess it is only due to my query vals.Any().
Thanks
Let me preface - I'm unfamiliar with the And method, but the .Equals(vals.Any()) doesn't look right to me. So, I assume that And takes a function returning a bool. What you're really looking for is to find out if the first character in the employee name is contained in the vals array:
employeepredicate = employeepredicate.And(
emp => vals.Contains(emp.EmployeeName.Substring(0, 1).ToLower()));