【发布时间】:2017-09-11 21:57:57
【问题描述】:
我正在使用 React Native 构建一个 Android 应用。
如何强制TextInput 为“unFocus”,这意味着光标在文本字段内闪烁。有isFocused() 和onFocus() 的功能,但我实际上如何让文本字段放弃焦点。您会认为一旦我按 Enter 键,它就会自动执行此操作,但事实并非如此。
import React, {Component} from 'react';
import { AppRegistry, Text, View, StyleSheet, TextInput, TouchableOpacity}
from 'react-native';
var SHA256 = require("crypto-js/sha256");
export default class LoginForm extends Component{
constructor(props){
super(props);
this.state = {
email: '',
password:''
};
}
tryLogin = () => {
if(this.state.email=="email123" && this.state.password == "password"){
console.log("password verified");
this.props.navigator.replace({
title: 'Dashboard'
});
}
console.log(this.state.email);
console.log(this.state.password);
console.log("Hash" + SHA256(this.state.password));
}
render(){
return(
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder="Email address"
placeholderTextColor="white"
onChangeText={(email) => this.setState({email})}>
</TextInput>
<TextInput style={styles.input}
placeholder="Password"
placeholderTextColor="white"
secureTextEntry
onChangeText={(password) => this.setState({password})}>
</TextInput>
<TouchableOpacity style={styles.loginButtonContainer} onPress={this.tryLogin}>
<Text style={styles.loginButtonText}>LOGIN</Text>
</TouchableOpacity>
</View>
);
}
}
AppRegistry.registerComponent('LoginForm', () => LoginForm);
const styles = StyleSheet.create({
container: {
padding: 20
},
input:{
height: 40,
backgroundColor: '#e74c3c',
marginBottom: 20,
color: 'white',
paddingHorizontal: 15,
opacity: .9
},
loginButtonContainer:{
justifyContent: 'center',
backgroundColor: '#bc4c3c',
paddingVertical:15
},
loginButtonText:{
textAlign:'center',
color:'white',
fontWeight: '700',
fontSize: 24
}
})
这对于真实用户来说可能并不重要,但我只是在模拟,如果我想重新加载它会很烦人。
【问题讨论】:
-
仅使用散列函数是不够的,仅添加盐对提高安全性无济于事。相反,iIterate over an HMAC with a random salt for about 100ms duration and save the salt with the hash.使用
PBKDF2、Rfc2898DeriveBytes、password_hash、Bcrypt等函数或类似函数。关键是让攻击者花费大量时间通过蛮力寻找密码。
标签: android react-native focus user-input react-native-android