![login.jpg](https://www.steemjiang.com:8081/ipfs/Qmcz3RQuTiPPtjjiChZSGE1q7f5oyXdQYBPyDsHYzFFFa8) Steem的登录有个麻烦事:Steem为了安全,设置了多层密码,什么posting key , active key......之类的,对于大部分人来讲,都是相当复杂的。而基于Steem设计的应用要想实现登录功能也绕不开这个麻烦事。 以前为了省事,做的SteemJiang是限定只能posting key登录!不过有些朋友反映SteemJiang登录不上去,也不知怎么查posting key。好吧,你就折腾着去查吧! **后来做链课,也充分考虑了多项因素,还是决定任意密码都可登录!** 如上图所示,用户可以使用posting key,也可以使用密码,都可以正常使用,无非是在登录时多做了一层逻辑判断。 在用密码登录时要多做一步生成密钥的动作。在js中是这个函数` steem.auth.toWif(account, password, role)` ,以用户名和密码来生成私钥。这个是固定算法,生成的结果会一致。然后,再用这个私钥登录就可以啰。 具体代码如下,有兴趣的朋友可以参考下: ```js steem-login(){ //用私钥或密码登录 this.isLoading = true let account = this.username this.steem.api.getAccounts([account], (err, result) => { if(result.length === 0){ this.isLoading = false alert("用户不存在!") }else{ //用户存在 let pubWif = result[0].posting.key_auths[0][0] let privWif = this.password let isvalid //判断是私钥还是密码 let res = this.steem.auth.isWif(privWif) if(res === true){ //是私钥 console.log(456, res, '是私钥!') try{ isvalid = this.steem.auth.wifIsValid(privWif, pubWif) } catch(e){ isvalid = 'false' } if(isvalid === true){ this.isLoading = false console.log(' Welcome.', account) this.$store.commit('saveUser', {username: account, password: privWif}) this.$router.push({path:'/'}) }else{ this.isLoading = false alert(`错误!请检查用户名和发贴密钥!`) } }else{ //是密码 console.log(458, res, '是密码') //获取发贴私钥 let role = ["posting"] let Wif = this.steem.auth.toWif(account, privWif, role) try{ isvalid = this.steem.auth.wifIsValid(Wif, pubWif) } catch(e){ isvalid = 'false' } if(isvalid === true){ this.isLoading = false console.log(' Welcome.', account) this.$store.commit('saveUser', {username: account, password: Wif}) this.$router.push({path:'/'}) }else{ this.isLoading = false alert(`错误!请检查用户名和密码!`) } } } }) } ```
post_id | 83,420,983 |
---|---|
author | lemooljiang |
permlink | nehth |
category | cn |
json_metadata | {"tags":["cn","network-institute","steemjs","steemdev","login"],"app":"steemit\/1.0","format":"markdown"} |
created | 2020-01-14 03:47:21 |
last_update | 2020-01-14 03:47:21 |
depth | 0 |
children | 2 |
net_rshares | 29,993,585,367,423 |
last_payout | 2020-01-21 03:47:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 4.231 SBD |
curator_payout_value | 4.002 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 2,167 |
author_reputation | 263,700,595,848,611 |
root_title | "SteemJs登录的逻辑 / 网络研习社#57" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
lemooljiang | 0 | 850,383,565,243 | 100% | ||
ace108 | 0 | 631,134,518,807 | 25% | ||
rivalhw | 0 | 1,742,505,487,221 | 100% | ||
sweetsssj | 0 | 19,712,448,763,576 | 50% | ||
dapeng | 0 | 31,077,908,855 | 100% | ||
bring | 0 | 39,171,031,358 | 100% | ||
elviento | 0 | 8,957,719,366 | 8.78% | ||
laodr | 0 | 91,205,136,069 | 100% | ||
imperfect-one | 0 | 1,599,259,140 | 5% | ||
htliao | 0 | 58,558,591,553 | 35% | ||
mys | 0 | 10,718,339,115 | 5% | ||
ew-and-patterns | 0 | 118,016,425,037 | 4% | ||
whd | 0 | 6,238,542,249 | 5% | ||
rafalski | 0 | 2,749,673,439 | 5% | ||
catwomanteresa | 0 | 144,528,055,718 | 50% | ||
liangfengyouren | 0 | 2,639,529,390 | 50% | ||
aafeng | 0 | 157,594,306,519 | 100% | ||
cn-reader | 0 | 11,902,131,162 | 50% | ||
tvb | 0 | 33,704,053,517 | 50% | ||
skenan | 0 | 11,224,272,277 | 50% | ||
tipu | 0 | 4,536,180,851,293 | 6% | ||
kimzwarch | 0 | 6,585,442,096 | 3.5% | ||
yellowbird | 0 | 33,957,577,135 | 100% | ||
davidke20 | 0 | 8,658,962,985 | 4% | ||
dancingapple | 0 | 11,873,833,320 | 50% | ||
xiaoshancun | 0 | 14,791,142,103 | 100% | ||
blc | 0 | 4,013,473,317 | 100% | ||
hqy | 0 | 43,911,380,778 | 100% | ||
zmm | 0 | 677,440,683 | 100% | ||
imisstheoldkanye | 0 | 2,793,419,771 | 1% | ||
jaff8 | 0 | 1,116,579,335 | 4.2% | ||
coindzs | 0 | 13,530,932,700 | 100% | ||
ooairbb | 0 | 288,080,088 | 100% | ||
raise-me-up | 0 | 0 | 0.01% | ||
fego | 0 | 7,391,306,645 | 4.2% | ||
ericet | 0 | 382,313,759,057 | 100% | ||
beleg | 0 | 2,229,033,940 | 5% | ||
angelinafx | 0 | 12,580,167,798 | 3.7% | ||
andrewma | 0 | 1,290,849,105 | 6% | ||
archisteem | 0 | 3,590,349,005 | 7.5% | ||
moneybaby | 0 | 788,427,069 | 2.5% | ||
suonghuynh | 0 | 618,123,652,226 | 3.7% | ||
mightypanda | 0 | 3,239,821,135 | 4.2% | ||
smartvote | 0 | 342,458,146,620 | 3.7% | ||
julian2013 | 0 | 236,522,533,412 | 50% | ||
laissez-faire | 0 | 38,590,610 | 100% | ||
sasaadrian | 0 | 19,733,323,812 | 20% | ||
steemersayu907 | 0 | 571,106,422 | 6% | ||
davidchen | 0 | 2,945,128,168 | 3.88% | ||
mia-cc | 0 | 12,093,441,873 | 100% | ||
kristinasiu | 0 | 2,939,305,311 | 3.96% | ||
bilpcoinpower | 0 | 0 | 1% | ||
ontoy | 0 | 0 | 100% |
@tipu curate
post_id | 83,421,406 |
---|---|
author | ericet |
permlink | re-lemooljiang-nehth-20200114t041553262z |
category | cn |
json_metadata | {"community":"busy","app":"busy\/2.5.6","format":"markdown","tags":["cn"],"users":["tipu"],"links":["\/@tipu"]} |
created | 2020-01-14 04:15:54 |
last_update | 2020-01-14 04:15:54 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2020-01-21 04:15:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 13 |
author_reputation | 359,381,366,380,462 |
root_title | "SteemJs登录的逻辑 / 网络研习社#57" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
<a href="https://tipu.online/curator?ericet" target="_blank">Upvoted 👌</a> (Mana: 0/4 - <a href="https://steemit.com/steem/@tipu/tipu-curate-project-update-recharging-curation-mana" target="_blank">need recharge</a>?)
post_id | 83,421,420 |
---|---|
author | tipu |
permlink | re-re-lemooljiang-nehth-20200114t041553262z-20200114t041626 |
category | cn |
json_metadata | {} |
created | 2020-01-14 04:16:45 |
last_update | 2020-01-14 04:16:45 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-01-21 04:16:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 225 |
author_reputation | 55,804,171,747,699 |
root_title | "SteemJs登录的逻辑 / 网络研习社#57" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |