Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Flatter中使用Firebase更改密码_Firebase_Dart_Firebase Authentication_Flutter - Fatal编程技术网

如何在Flatter中使用Firebase更改密码

如何在Flatter中使用Firebase更改密码,firebase,dart,firebase-authentication,flutter,Firebase,Dart,Firebase Authentication,Flutter,我想在Flatter中使用Firebase更改当前用户密码。 有谁能帮助我实现更改密码的方法吗?目前不支持这种方法 合并此pull请求时,Flatter firebase_auth包将支持该请求。目前不支持该请求 当合并此pull请求时,Flatter firebase_auth软件包将支持该功能。正如@Gunter提到的,该功能目前仍然不可用,您可以暂时使用更改密码的方式 import 'package:http/http.dart' as http; import 'dart:convert

我想在Flatter中使用Firebase更改当前用户密码。
有谁能帮助我实现更改密码的方法吗?

目前不支持这种方法


合并此pull请求时,Flatter firebase_auth包将支持该请求。

目前不支持该请求

当合并此pull请求时,Flatter firebase_auth软件包将支持该功能。

正如@Gunter提到的,该功能目前仍然不可用,您可以暂时使用更改密码的方式

import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:async';

Future<Null> changePassword(String newPassword) async {
  const String API_KEY = 'YOUR_API_KEY';
  final String changePasswordUrl =
      'https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key=$API_KEY';

      final String idToken = await user.getIdToken(); // where user is FirebaseUser user

    final Map<String, dynamic> payload = {
      'email': idToken,
      'password': newPassword,
      'returnSecureToken': true
    };

  await http.post(changePasswordUrl, 
    body: json.encode(payload), 
    headers: {'Content-Type': 'application/json'},  
  )
}
您可以使用对象上的方法获取idToken

您可以在控制台中的项目设置下获取firebase api密钥

正如@Gunter提到的,该功能目前仍然不可用,您可以暂时使用更改密码的方式

import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:async';

Future<Null> changePassword(String newPassword) async {
  const String API_KEY = 'YOUR_API_KEY';
  final String changePasswordUrl =
      'https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key=$API_KEY';

      final String idToken = await user.getIdToken(); // where user is FirebaseUser user

    final Map<String, dynamic> payload = {
      'email': idToken,
      'password': newPassword,
      'returnSecureToken': true
    };

  await http.post(changePasswordUrl, 
    body: json.encode(payload), 
    headers: {'Content-Type': 'application/json'},  
  )
}
您可以使用对象上的方法获取idToken

您可以在控制台中的项目设置下获取firebase api密钥


我知道这是一篇迟到的帖子,但现在可以更改登录用户的密码了。请确保通知用户再次登录,因为这是一项敏感操作

void _changePassword(String password) async{
   //Create an instance of the current user. 
    FirebaseUser user = await FirebaseAuth.instance.currentUser();
   
    //Pass in the password to updatePassword.
    user.updatePassword(password).then((_){
      print("Successfully changed password");
    }).catchError((error){
      print("Password can't be changed" + error.toString());
      //This might happen, when the wrong password is in, the user isn't found, or if the user hasn't logged in recently.
    });
  }

我知道这是一篇迟到的帖子,但现在可以更改登录用户的密码了。请确保通知用户再次登录,因为这是一项敏感操作

void _changePassword(String password) async{
   //Create an instance of the current user. 
    FirebaseUser user = await FirebaseAuth.instance.currentUser();
   
    //Pass in the password to updatePassword.
    user.updatePassword(password).then((_){
      print("Successfully changed password");
    }).catchError((error){
      print("Password can't be changed" + error.toString());
      //This might happen, when the wrong password is in, the user isn't found, or if the user hasn't logged in recently.
    });
  }

这应根据最新版本的firebase:

final FirebaseAuth FirebaseAuth=FirebaseAuth.instance; User currentUser=firebaseAuth.currentUser; currentUser.updatePasswordnewpassword.then{ //密码已更新。 }CatchErrorer先生{ //发生了一个错误。 }
这应根据最新版本的firebase:

final FirebaseAuth FirebaseAuth=FirebaseAuth.instance; User currentUser=firebaseAuth.currentUser; currentUser.updatePasswordnewpassword.then{ //密码已更新。 }CatchErrorer先生{ //发生了一个错误。 }